forked from boostorg/iterator
filter_iterator
[SVN r850]
This commit is contained in:
1 parent
04f037ae5c
commit
6141b83c5e
3 files changed
+178
-4
No files matched your search
@@ -4,5 +4,6 @@ run concept_tests.cpp ;
|
||||
run iterator_adaptor_cc.cpp ;
|
||||
run transform_iterator_test.cpp ;
|
||||
run indirect_iterator_test.cpp ;
|
||||
run filter_iterator_test.cpp ;
|
||||
compile-fail interoperable_fail.cpp ;
|
||||
compile-fail is_convertible_fail.cpp ;
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright David Abrahams 2003. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#include <boost/iterator/iterator_adaptors.hpp>
|
||||
#include <boost/iterator/new_iterator_tests.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
|
||||
using boost::dummyT;
|
||||
|
||||
struct one_or_four {
|
||||
bool operator()(dummyT x) const {
|
||||
return x.foo() == 1 || x.foo() == 4;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
namespace boost { namespace detail
|
||||
{
|
||||
template<> struct iterator_traits<dummyT*>
|
||||
: ptr_iter_traits<dummyT> {};
|
||||
}}
|
||||
#endif
|
||||
|
||||
|
||||
// Test filter iterator
|
||||
int main()
|
||||
{
|
||||
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
|
||||
dummyT(3), dummyT(4), dummyT(5) };
|
||||
const int N = sizeof(array)/sizeof(dummyT);
|
||||
|
||||
typedef boost::filter_iterator<one_or_four, dummyT*> filter_iter;
|
||||
|
||||
boost::forward_iterator_test(
|
||||
filter_iter(one_or_four(), array, array+N)
|
||||
, dummyT(1), dummyT(4));
|
||||
|
||||
# if 0
|
||||
BOOST_STATIC_ASSERT(
|
||||
(!boost::detail::is_bidirectional_traversal_iterator<
|
||||
boost::traversal_category<filter_iter>::type
|
||||
>::value) );
|
||||
# endif
|
||||
|
||||
// On compilers not supporting partial specialization, we can do more type
|
||||
// deduction with deque iterators than with pointers... unless the library
|
||||
// is broken ;-(
|
||||
std::deque<dummyT> array2;
|
||||
std::copy(array+0, array+N, std::back_inserter(array2));
|
||||
boost::forward_iterator_test(
|
||||
boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
boost::forward_iterator_test(
|
||||
boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
boost::forward_iterator_test(
|
||||
boost::make_filter_iterator(
|
||||
one_or_four()
|
||||
, boost::make_reverse_iterator(array2.end())
|
||||
, boost::make_reverse_iterator(array2.begin())
|
||||
),
|
||||
dummyT(4), dummyT(1));
|
||||
|
||||
boost::forward_iterator_test(
|
||||
filter_iter(array+0, array+N),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
boost::forward_iterator_test(
|
||||
filter_iter(one_or_four(), array, array + N),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
std::cout << "test successful " << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user