diff options
Diffstat (limited to 'boost/iterator/function_input_iterator.hpp')
-rw-r--r-- | boost/iterator/function_input_iterator.hpp | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/boost/iterator/function_input_iterator.hpp b/boost/iterator/function_input_iterator.hpp index f3e9de92e4..caa6272958 100644 --- a/boost/iterator/function_input_iterator.hpp +++ b/boost/iterator/function_input_iterator.hpp @@ -11,34 +11,53 @@ #include <boost/config.hpp> #include <boost/assert.hpp> +#include <boost/core/addressof.hpp> #include <boost/mpl/if.hpp> #include <boost/function_types/is_function_pointer.hpp> -#include <boost/function_types/is_function_reference.hpp> #include <boost/function_types/result_type.hpp> #include <boost/iterator/iterator_facade.hpp> #include <boost/none.hpp> #include <boost/optional/optional.hpp> #include <boost/utility/result_of.hpp> +#ifdef BOOST_RESULT_OF_USE_TR1 +#include <boost/type_traits/is_function.hpp> +#endif + namespace boost { namespace iterators { namespace impl { + // Computes the return type of an lvalue-call with an empty argument, + // i.e. decltype(declval<F&>()()). F should be a nullary lvalue-callable + // or function. + template <class F> + struct result_of_nullary_lvalue_call + { + typedef typename result_of< +#ifdef BOOST_RESULT_OF_USE_TR1 + typename mpl::if_<is_function<F>, F&, F>::type() +#else + F&() +#endif + >::type type; + }; + template <class Function, class Input> class function_input_iterator : public iterator_facade< function_input_iterator<Function, Input>, - BOOST_DEDUCED_TYPENAME result_of<Function ()>::type, + typename result_of_nullary_lvalue_call<Function>::type, single_pass_traversal_tag, - BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const & + typename result_of_nullary_lvalue_call<Function>::type const & > { public: function_input_iterator() {} function_input_iterator(Function & f_, Input state_ = Input()) - : f(&f_), state(state_) {} + : f(boost::addressof(f_)), state(state_) {} void increment() { if(value) @@ -48,7 +67,7 @@ namespace iterators { ++state; } - BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const & + typename result_of_nullary_lvalue_call<Function>::type const & dereference() const { return (value ? value : value = (*f)()).get(); } @@ -60,7 +79,7 @@ namespace iterators { private: Function * f; Input state; - mutable optional<BOOST_DEDUCED_TYPENAME result_of<Function ()>::type> value; + mutable optional<typename result_of_nullary_lvalue_call<Function>::type> value; }; template <class Function, class Input> @@ -100,16 +119,6 @@ namespace iterators { mutable optional<typename function_types::result_type<Function>::type> value; }; - template <class Function, class Input> - class function_reference_input_iterator - : public function_pointer_input_iterator<Function*,Input> - { - public: - function_reference_input_iterator(Function & f_, Input state_ = Input()) - : function_pointer_input_iterator<Function*,Input>(&f_, state_) - {} - }; - } // namespace impl template <class Function, class Input> @@ -117,21 +126,13 @@ namespace iterators { : public mpl::if_< function_types::is_function_pointer<Function>, impl::function_pointer_input_iterator<Function,Input>, - typename mpl::if_< - function_types::is_function_reference<Function>, - impl::function_reference_input_iterator<Function,Input>, - impl::function_input_iterator<Function,Input> - >::type + impl::function_input_iterator<Function,Input> >::type { typedef typename mpl::if_< function_types::is_function_pointer<Function>, impl::function_pointer_input_iterator<Function,Input>, - typename mpl::if_< - function_types::is_function_reference<Function>, - impl::function_reference_input_iterator<Function,Input>, - impl::function_input_iterator<Function,Input> - >::type + impl::function_input_iterator<Function,Input> >::type base_type; public: function_input_iterator(Function & f, Input i) |