Get examples working, mostly. Some interface expansion for a few of

the adaptors, allowing default construction of UnaryFunction and
Predicate arguments when they are class types.


[SVN r19081]
This commit is contained in:
Dave Abrahams
2003-07-12 04:15:13 +00:00
parent 1d6f36e35d
commit 4c8415a99f
3 changed files with 94 additions and 20 deletions

View File

@ -56,8 +56,15 @@ namespace boost
satisfy_predicate(); satisfy_predicate();
} }
filter_iterator(Iterator x, Iterator end = Iterator()) // don't provide this constructor if UnaryFunction is a
: super_t(x), m_predicate(), m_end(end) // function pointer type. Too dangerous.
filter_iterator(
typename detail::enable_if<
is_class<Predicate>
, Iterator
>::type x
, Iterator end = Iterator())
: super_t(x), m_predicate(), m_end(end)
{ {
satisfy_predicate(); satisfy_predicate();
} }
@ -104,6 +111,22 @@ namespace boost
return filter_iterator<Predicate,Iterator>(f,x,end); return filter_iterator<Predicate,Iterator>(f,x,end);
} }
template <class Predicate, class Iterator>
filter_iterator<Predicate,Iterator>
make_filter_iterator(
typename detail::enable_if<
is_class<Predicate>
, Iterator
>::type x
, Iterator end = Iterator()
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
, Predicate* = 0
#endif
)
{
return filter_iterator<Predicate,Iterator>(x,end);
}
} // namespace boost } // namespace boost
#endif // BOOST_FILTER_ITERATOR_23022003THW_HPP #endif // BOOST_FILTER_ITERATOR_23022003THW_HPP

View File

@ -14,10 +14,11 @@
#include <boost/iterator/detail/enable_if.hpp> #include <boost/iterator/detail/enable_if.hpp>
#include <boost/iterator/iterator_adaptor.hpp> #include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_categories.hpp> #include <boost/iterator/iterator_categories.hpp>
#include <boost/mpl/and.hpp> #include <boost/mpl/not.hpp>
#include <boost/mpl/bool.hpp> #include <boost/mpl/bool.hpp>
#include <boost/type_traits/function_traits.hpp> #include <boost/type_traits/function_traits.hpp>
#include <boost/type_traits/is_const.hpp> #include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_function.hpp> #include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/is_reference.hpp> #include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/remove_const.hpp>
@ -96,7 +97,6 @@ namespace boost
, result_type , result_type
> type; > type;
}; };
} }
template <class UnaryFunction, class Iterator, class Reference, class Value> template <class UnaryFunction, class Iterator, class Reference, class Value>
@ -115,10 +115,28 @@ namespace boost
transform_iterator(Iterator const& x, UnaryFunction f) transform_iterator(Iterator const& x, UnaryFunction f)
: super_t(x), m_f(f) { } : super_t(x), m_f(f) { }
// don't provide this constructor if UnaryFunction is a
// function pointer type. Too dangerous.
transform_iterator(
// Sadly, GCC 3.2 seems to choke on the enable_if when
// UnaryFunction is a plain function pointer
#if BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(3)) \
&& BOOST_WORKAROUND(__GNUC_MINOR__, BOOST_TESTED_AT(2))
Iterator const& x
#else
typename detail::enable_if<
is_class<UnaryFunction>
, Iterator const&
>::type x
#endif
)
: super_t(x)
{}
template<class OtherIterator> template<class OtherIterator>
transform_iterator( transform_iterator(
transform_iterator<UnaryFunction, OtherIterator, Reference, Value> const& t transform_iterator<UnaryFunction, OtherIterator, Reference, Value> const& t
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
) )
: super_t(t.base()), m_f(t.functor()) {} : super_t(t.base()), m_f(t.functor()) {}
@ -135,9 +153,23 @@ namespace boost
}; };
template <class UnaryFunction, class Iterator> template <class UnaryFunction, class Iterator>
transform_iterator<UnaryFunction, Iterator> make_transform_iterator(Iterator it, UnaryFunction fun) transform_iterator<UnaryFunction, Iterator>
make_transform_iterator(Iterator it, UnaryFunction fun)
{ {
return transform_iterator<UnaryFunction, Iterator>(it, fun); return transform_iterator<UnaryFunction, Iterator>(it, fun);
}
template <class UnaryFunction, class Iterator>
// don't provide this generator if UnaryFunction is a
// function pointer type. Too dangerous. We should probably
// find a cheaper test than is_class<>
typename detail::enable_if<
is_class<UnaryFunction>
, transform_iterator<UnaryFunction, Iterator>
>::type
make_transform_iterator(Iterator it)
{
return transform_iterator<UnaryFunction, Iterator>(it, UnaryFunction());
} }
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)

View File

@ -1,14 +1,33 @@
# 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.
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
include testing.jam ; include testing.jam ;
run unit_tests.cpp ;
run concept_tests.cpp ; test-suite iterator
run iterator_adaptor_cc.cpp ; : [ run unit_tests.cpp ]
run iterator_adaptor_test.cpp ; [ run concept_tests.cpp ]
compile iterator_archetype_cc.cpp ; [ run iterator_adaptor_cc.cpp ]
run transform_iterator_test.cpp ; [ run iterator_adaptor_test.cpp ]
run indirect_iterator_test.cpp ; [ compile iterator_archetype_cc.cpp ]
run filter_iterator_test.cpp ; [ run transform_iterator_test.cpp ]
run reverse_iterator_test.cpp ; [ run indirect_iterator_test.cpp ]
run counting_iterator_test.cpp ; [ run filter_iterator_test.cpp ]
run is_convertible_fail.cpp ; # test changed to expected success, so that we catch compilation failures. [ run reverse_iterator_test.cpp ]
compile-fail interoperable_fail.cpp ; [ run counting_iterator_test.cpp ]
[ run ../../utility/iterator_adaptor_examples.cpp ]
[ run ../../utility/counting_iterator_example.cpp ]
[ run ../../utility/filter_iterator_example.cpp ]
[ run ../../utility/fun_out_iter_example.cpp ]
[ run ../../utility/indirect_iterator_example.cpp ]
[ run ../../utility/projection_iterator_example.cpp ]
[ run ../../utility/reverse_iterator_example.cpp ]
[ run ../../utility/transform_iterator_example.cpp ]
[ run is_convertible_fail.cpp ] # test changed to expected success, so that we catch compilation failures.
[ compile-fail interoperable_fail.cpp ]
;