Mercurial > code
changeset 264:02aea4deed32
TreeNode:
* add some noexcept
* take a signed int in remove to make chained expression cleaner
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 14 Oct 2014 11:40:40 +0200 |
parents | fb91d4dc046b |
children | 4ddc300e8998 |
files | C++/TreeNode.h |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/TreeNode.h Tue Oct 14 09:14:33 2014 +0200 +++ b/C++/TreeNode.h Tue Oct 14 11:40:40 2014 +0200 @@ -270,7 +270,7 @@ * * @return the number of children */ - unsigned countChildren() const + unsigned countChildren() const noexcept { return static_cast<unsigned>(m_children.size()); } @@ -308,7 +308,7 @@ * * @return true if root */ - bool isRoot() const + bool isRoot() const noexcept { return m_parent == nullptr; } @@ -318,7 +318,7 @@ * * @return true if leaf */ - bool isLeaf() const + bool isLeaf() const noexcept { return m_children.size() == 0; } @@ -329,9 +329,9 @@ * @param index the position index * @throw std::out_of_range if index is out of bounds */ - void remove(unsigned index) + void remove(int index) { - if (index >= m_children.size()) + if (index < 0 || index >= m_children.size()) throw std::out_of_range("index is out of range"); m_children.erase(m_children.begin() + index); @@ -380,7 +380,7 @@ * @return the index or -1 if not found * @see indexOfSame */ - int indexOf(const T &child) const + int indexOf(const T &child) const noexcept { for (unsigned i = 0; i < m_children.size(); ++i) if (m_children[i]->value.get() == &child) @@ -397,7 +397,7 @@ * @see indexOf */ template <typename Value> - int indexOfSame(const Value &value, typename std::enable_if<TypeTraits<Value>::equalityComparable>::type * = nullptr) + int indexOfSame(const Value &value, typename std::enable_if<TypeTraits<Value>::equalityComparable>::type * = nullptr) const noexcept { for (unsigned i = 0; i < m_children.size(); ++i) if (*m_children[i]->value == value)