fix find_s and find_if_s to return the end iterator when item not found

[SVN r73669]
This commit is contained in:
Eric Niebler
2011-08-11 17:49:02 +00:00
parent b83a2954f5
commit 5d07df005b
4 changed files with 87 additions and 10 deletions

View File

@ -13,6 +13,8 @@
#include <boost/mpl/placeholders.hpp>
#include <boost/type_traits/is_same.hpp>
struct not_there {};
template<typename Tree>
void
process_tree(Tree const &tree)
@ -22,6 +24,7 @@ process_tree(Tree const &tree)
typedef typename fusion::result_of::find_if_s<Tree const, is_same<_,short> >::type short_iter;
typedef typename fusion::result_of::find_if_s<Tree const, is_same<_,float> >::type float_iter;
typedef typename fusion::result_of::find_if_s<Tree const, is_same<_,not_there> >::type not_there_iter;
// find_if_s of a segmented data structure returns generic
// segmented iterators
@ -31,6 +34,10 @@ process_tree(Tree const &tree)
// they behave like ordinary Fusion iterators ...
BOOST_TEST((*si == short('d')));
BOOST_TEST((*fi == float(1)));
// Searching for something that's not there should return the end iterator.
not_there_iter nti = fusion::find_if_s<is_same<_,not_there> >(tree);
BOOST_TEST((nti == fusion::end(tree)));
}
int

View File

@ -11,6 +11,8 @@
#include <boost/fusion/container/ext_/tree.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
struct not_there {};
template<typename Tree>
void
process_tree(Tree const &tree)
@ -19,6 +21,7 @@ process_tree(Tree const &tree)
typedef typename fusion::result_of::find_s<Tree const, short>::type short_iter;
typedef typename fusion::result_of::find_s<Tree const, float>::type float_iter;
typedef typename fusion::result_of::find_s<Tree const, not_there>::type not_there_iter;
// find_if_s of a segmented data structure returns generic
// segmented iterators
@ -28,6 +31,10 @@ process_tree(Tree const &tree)
// they behave like ordinary Fusion iterators ...
BOOST_TEST((*si == short('d')));
BOOST_TEST((*fi == float(1)));
// Searching for something that's not there should return the end iterator.
not_there_iter nti = fusion::find_s<not_there>(tree);
BOOST_TEST((nti == fusion::end(tree)));
}
int