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,7 +56,14 @@ namespace boost
satisfy_predicate();
}
filter_iterator(Iterator x, Iterator end = Iterator())
// don't provide this constructor if UnaryFunction is a
// 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();
@ -104,6 +111,22 @@ namespace boost
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
#endif // BOOST_FILTER_ITERATOR_23022003THW_HPP

View File

@ -14,10 +14,11 @@
#include <boost/iterator/detail/enable_if.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/type_traits/function_traits.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_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
@ -96,7 +97,6 @@ namespace boost
, result_type
> type;
};
}
template <class UnaryFunction, class Iterator, class Reference, class Value>
@ -115,6 +115,24 @@ namespace boost
transform_iterator(Iterator const& x, UnaryFunction 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>
transform_iterator(
transform_iterator<UnaryFunction, OtherIterator, Reference, Value> const& t
@ -135,11 +153,25 @@ namespace boost
};
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);
}
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)
template <class Return, class Argument, class Iterator>
transform_iterator< Return (*)(Argument), Iterator, Return>

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) ;
include testing.jam ;
run unit_tests.cpp ;
run concept_tests.cpp ;
run iterator_adaptor_cc.cpp ;
run iterator_adaptor_test.cpp ;
compile iterator_archetype_cc.cpp ;
run transform_iterator_test.cpp ;
run indirect_iterator_test.cpp ;
run filter_iterator_test.cpp ;
run reverse_iterator_test.cpp ;
run counting_iterator_test.cpp ;
run is_convertible_fail.cpp ; # test changed to expected success, so that we catch compilation failures.
compile-fail interoperable_fail.cpp ;
test-suite iterator
: [ run unit_tests.cpp ]
[ run concept_tests.cpp ]
[ run iterator_adaptor_cc.cpp ]
[ run iterator_adaptor_test.cpp ]
[ compile iterator_archetype_cc.cpp ]
[ run transform_iterator_test.cpp ]
[ run indirect_iterator_test.cpp ]
[ run filter_iterator_test.cpp ]
[ run reverse_iterator_test.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 ]
;