From 4c8415a99fb5fd28aaf0364896b867e63aee1eb7 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 12 Jul 2003 04:15:13 +0000 Subject: [PATCH] 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] --- include/boost/iterator/filter_iterator.hpp | 27 +++++++++++- include/boost/iterator/transform_iterator.hpp | 44 ++++++++++++++++--- test/Jamfile | 43 +++++++++++++----- 3 files changed, 94 insertions(+), 20 deletions(-) diff --git a/include/boost/iterator/filter_iterator.hpp b/include/boost/iterator/filter_iterator.hpp index ae46fba..547513f 100644 --- a/include/boost/iterator/filter_iterator.hpp +++ b/include/boost/iterator/filter_iterator.hpp @@ -56,8 +56,15 @@ namespace boost satisfy_predicate(); } - filter_iterator(Iterator x, Iterator end = Iterator()) - : super_t(x), m_predicate(), m_end(end) + // don't provide this constructor if UnaryFunction is a + // function pointer type. Too dangerous. + filter_iterator( + typename detail::enable_if< + is_class + , 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(f,x,end); } + template + filter_iterator + make_filter_iterator( + typename detail::enable_if< + is_class + , Iterator + >::type x + , Iterator end = Iterator() +#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) + , Predicate* = 0 +#endif + ) + { + return filter_iterator(x,end); + } + } // namespace boost #endif // BOOST_FILTER_ITERATOR_23022003THW_HPP diff --git a/include/boost/iterator/transform_iterator.hpp b/include/boost/iterator/transform_iterator.hpp index 26ed994..f560116 100644 --- a/include/boost/iterator/transform_iterator.hpp +++ b/include/boost/iterator/transform_iterator.hpp @@ -14,10 +14,11 @@ #include #include #include -#include +#include #include #include #include +#include #include #include #include @@ -96,7 +97,6 @@ namespace boost , result_type > type; }; - } template @@ -115,10 +115,28 @@ 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 + , Iterator const& + >::type x +#endif + ) + : super_t(x) + {} + template transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 + transform_iterator const& t + , typename enable_if_convertible::type* = 0 ) : super_t(t.base()), m_f(t.functor()) {} @@ -135,9 +153,23 @@ namespace boost }; template - transform_iterator make_transform_iterator(Iterator it, UnaryFunction fun) + transform_iterator + make_transform_iterator(Iterator it, UnaryFunction fun) { - return transform_iterator(it, fun); + return transform_iterator(it, fun); + } + + template + // 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 + , transform_iterator + >::type + make_transform_iterator(Iterator it) + { + return transform_iterator(it, UnaryFunction()); } #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) diff --git a/test/Jamfile b/test/Jamfile index 75d3d1f..6cdcefc 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ] +; \ No newline at end of file