table: declare name_tree::Range type
Declare that NameTree enumeration returns name_tree::Range type
instead of an unspecified type usable with range-based for.
refs #3738
Change-Id: I132c583704d0c6164077abf70a694e833b448e85
diff --git a/daemon/table/name-tree-iterator.cpp b/daemon/table/name-tree-iterator.cpp
index 8750867..d7c7362 100644
--- a/daemon/table/name-tree-iterator.cpp
+++ b/daemon/table/name-tree-iterator.cpp
@@ -29,17 +29,20 @@
#include <boost/concept/assert.hpp>
#include <boost/concept_check.hpp>
+#include <boost/range/concepts.hpp>
#include <type_traits>
namespace nfd {
namespace name_tree {
-NFD_LOG_INIT("NameTreeIterator");
-
BOOST_CONCEPT_ASSERT((boost::ForwardIterator<Iterator>));
static_assert(std::is_default_constructible<Iterator>::value,
"Iterator must be default-constructible");
+BOOST_CONCEPT_ASSERT((boost::ForwardRangeConcept<Range>));
+
+NFD_LOG_INIT("NameTreeIterator");
+
Iterator::Iterator()
: m_entry(nullptr)
, m_ref(nullptr)
diff --git a/daemon/table/name-tree-iterator.hpp b/daemon/table/name-tree-iterator.hpp
index ecde5bd..cb0921d 100644
--- a/daemon/table/name-tree-iterator.hpp
+++ b/daemon/table/name-tree-iterator.hpp
@@ -195,6 +195,13 @@
EntrySelector m_pred;
};
+/** \brief a Forward Range of name tree entries
+ *
+ * This type has .begin() and .end() methods which return Iterator.
+ * This type is usable with range-based for.
+ */
+typedef boost::iterator_range<Iterator> Range;
+
} // namespace name_tree
} // namespace nfd
diff --git a/daemon/table/name-tree.hpp b/daemon/table/name-tree.hpp
index 0c24654..5c31103 100644
--- a/daemon/table/name-tree.hpp
+++ b/daemon/table/name-tree.hpp
@@ -36,8 +36,6 @@
class NameTree : noncopyable
{
public:
- typedef Iterator const_iterator;
-
explicit
NameTree(size_t nBuckets = 1024);
@@ -164,9 +162,7 @@
const EntrySelector& entrySelector = AnyEntry()) const;
/** \brief all-prefixes match lookup
- * \return an unspecified type that have .begin() and .end() methods
- * and is usable with range-based for.
- * Every entry in the range has a name that is a prefix of \p name ,
+ * \return a range where every entry has a name that is a prefix of \p name ,
* and matches \p entrySelector.
*
* Example:
@@ -184,15 +180,15 @@
* If a name tree entry whose name is a prefix of \p name is deleted
* during the enumeration, undefined behavior may occur.
*/
- boost::iterator_range<const_iterator>
+ Range
findAllMatches(const Name& name,
const EntrySelector& entrySelector = AnyEntry()) const;
public: // enumeration
+ typedef Iterator const_iterator;
+
/** \brief enumerate all entries
- * \return an unspecified type that have .begin() and .end() methods
- * and is usable with range-based for.
- * Every entry in the range matches \p entrySelector.
+ * \return a range where every entry matches \p entrySelector
*
* Example:
* \code
@@ -205,13 +201,11 @@
* \warning If a name tree entry is inserted or deleted during the enumeration,
* it may cause the enumeration to skip entries or visit some entries twice.
*/
- boost::iterator_range<const_iterator>
+ Range
fullEnumerate(const EntrySelector& entrySelector = AnyEntry()) const;
/** \brief enumerate all entries under a prefix
- * \return an unspecified type that have .begin() and .end() methods
- * and is usable with range-based for.
- * Every entry in the range has a name that starts with \p prefix,
+ * \return a range where every entry has a name that starts with \p prefix,
* and matches \p entrySubTreeSelector.
*
* Example:
@@ -227,7 +221,7 @@
* \warning If a name tree entry under \p prefix is inserted or deleted during the enumeration,
* it may cause the enumeration to skip entries or visit some entries twice.
*/
- boost::iterator_range<const_iterator>
+ Range
partialEnumerate(const Name& prefix,
const EntrySubTreeSelector& entrySubTreeSelector = AnyEntrySubTree()) const;