From fd1445140f2a38b29d30029bb93ad481a703664b Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 6 Feb 2025 00:58:03 +0300 Subject: [PATCH] Removed usage of FunctionTypes in function_input_iterator.hpp. This effectively removes usage of MPL in function_input_iterator.hpp and also simplifies implementation. --- CMakeLists.txt | 1 - build.jam | 1 - .../iterator/function_input_iterator.hpp | 246 +++++++++--------- 3 files changed, 116 insertions(+), 132 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bedf55b..0706aeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ target_link_libraries(boost_iterator Boost::config Boost::core Boost::detail - Boost::function_types Boost::fusion Boost::mpl Boost::optional diff --git a/build.jam b/build.jam index 9f47fcb..ecc77c7 100644 --- a/build.jam +++ b/build.jam @@ -11,7 +11,6 @@ constant boost_dependencies : /boost/config//boost_config /boost/core//boost_core /boost/detail//boost_detail - /boost/function_types//boost_function_types /boost/fusion//boost_fusion /boost/mpl//boost_mpl /boost/optional//boost_optional diff --git a/include/boost/iterator/function_input_iterator.hpp b/include/boost/iterator/function_input_iterator.hpp index be72a42..50d2078 100644 --- a/include/boost/iterator/function_input_iterator.hpp +++ b/include/boost/iterator/function_input_iterator.hpp @@ -6,163 +6,150 @@ // http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BOOST_FUNCTION_INPUT_ITERATOR -#define BOOST_FUNCTION_INPUT_ITERATOR +#ifndef BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_ +#define BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_ -#include #include +#include -#include -#include -#include #include -#include +#include +#include #include -#include namespace boost { - namespace iterators { - template - class function_input_iterator; +template< typename Function, typename Input > +class function_input_iterator; - namespace impl { +namespace detail { - // Computes the return type of an lvalue-call with an empty argument, - // i.e. decltype(declval()()). F should be a nullary lvalue-callable - // or function. - template - struct result_of_nullary_lvalue_call - { - typedef typename result_of< -#ifdef BOOST_RESULT_OF_USE_TR1 - typename std::conditional::value, F&, F>::type() -#else - F&() -#endif - >::type type; - }; +template< typename Function, typename Input > +using function_input_iterator_facade_base_t = iterator_facade< + iterators::function_input_iterator< Function, Input >, + decltype(std::declval< Function& >()()), + single_pass_traversal_tag, + decltype(std::declval< Function& >()()) const& +>; - template - class function_object_input_iterator : - public iterator_facade< - iterators::function_input_iterator, - typename result_of_nullary_lvalue_call::type, - single_pass_traversal_tag, - typename result_of_nullary_lvalue_call::type const& - > - { - public: - function_object_input_iterator() {} - function_object_input_iterator(Function& f_, Input state_ = Input()) - : f(std::addressof(f_)), state(state_) {} +template< typename Function, typename Input > +class function_object_input_iterator : + public function_input_iterator_facade_base_t< Function, Input > +{ +private: + using base_type = function_input_iterator_facade_base_t< Function, Input >; - void increment() { - if (value) - value = none; - else - (*f)(); - ++state; - } +protected: + using function_arg_type = Function&; - typename result_of_nullary_lvalue_call::type const& - dereference() const { - if (!value) - value = (*f)(); - return value.get(); - } +public: + using value_type = typename base_type::value_type; - bool equal(function_object_input_iterator const& other) const { - return f == other.f && state == other.state; - } +public: + function_object_input_iterator(function_arg_type f, Input state) : + m_f(std::addressof(f)), m_state(state) + {} - private: - Function * f; - Input state; - mutable optional::type> value; - }; +protected: + typename std::add_pointer< Function >::type m_f; + Input m_state; + mutable optional< value_type > m_value; +}; - template - class function_pointer_input_iterator : - public iterator_facade< - iterators::function_input_iterator, - typename function_types::result_type::type, - single_pass_traversal_tag, - typename function_types::result_type::type const& - > - { - public: - function_pointer_input_iterator() {} - function_pointer_input_iterator(Function& f_, Input state_ = Input()) - : f(f_), state(state_) {} +template< typename Function, typename Input > +class function_pointer_input_iterator : + public function_input_iterator_facade_base_t< Function, Input > +{ +private: + using base_type = function_input_iterator_facade_base_t< Function, Input >; - void increment() { - if (value) - value = none; - else - (*f)(); - ++state; - } +protected: + using function_arg_type = Function; - typename function_types::result_type::type const& - dereference() const { - if (!value) - value = (*f)(); - return value.get(); - } +public: + using value_type = typename base_type::value_type; - bool equal(function_pointer_input_iterator const& other) const { - return f == other.f && state == other.state; - } +public: + function_pointer_input_iterator(function_arg_type f, Input state) : + m_f(f), m_state(state) + {} - private: - Function f; - Input state; - mutable optional::type> value; - }; +protected: + Function m_f; + Input m_state; + mutable optional< value_type > m_value; +}; - } // namespace impl +template< typename Function, typename Input > +using function_input_iterator_base_t = typename std::conditional< + detail::conjunction< + std::is_pointer< Function >, + std::is_function< typename std::remove_pointer< Function >::type > + >::value, + detail::function_pointer_input_iterator< Function, Input >, + detail::function_object_input_iterator< Function, Input > +>::type; - template - class function_input_iterator : - public std::conditional< - function_types::is_function_pointer::value, - impl::function_pointer_input_iterator, - impl::function_object_input_iterator - >::type +} // namespace detail + +template< typename Function, typename Input > +class function_input_iterator : + public detail::function_input_iterator_base_t< Function, Input > +{ +private: + using base_type = detail::function_input_iterator_base_t< Function, Input >; + using function_arg_type = typename base_type::function_arg_type; + +public: + using reference = typename base_type::reference; + +public: + function_input_iterator(function_arg_type f, Input i) : + base_type(f, i) + {} + + void increment() { - typedef typename std::conditional< - function_types::is_function_pointer::value, - impl::function_pointer_input_iterator, - impl::function_object_input_iterator - >::type base_type; - public: - function_input_iterator(Function& f, Input i) - : base_type(f, i) {} - }; - - template - inline function_input_iterator - make_function_input_iterator(Function& f, Input state) { - typedef function_input_iterator result_t; - return result_t(f, state); + if (this->m_value) + this->m_value.reset(); + else + (*this->m_f)(); + ++this->m_state; } - template - inline function_input_iterator - make_function_input_iterator(Function* f, Input state) { - typedef function_input_iterator result_t; - return result_t(f, state); + reference dereference() const + { + if (!this->m_value) + this->m_value = (*this->m_f)(); + return this->m_value.get(); } - struct infinite + bool equal(function_input_iterator const& other) const { - infinite& operator++() { return *this; } - infinite& operator++(int) { return *this; } - bool operator==(infinite&) const { return false; }; - bool operator==(infinite const&) const { return false; }; - }; + return this->m_f == other.m_f && this->m_state == other.m_state; + } +}; + +template< typename Function, typename Input > +inline function_input_iterator< Function, Input > make_function_input_iterator(Function& f, Input state) +{ + return function_input_iterator< Function, Input >(f, state); +} + +template< typename Function, typename Input > +inline function_input_iterator< Function*, Input > make_function_input_iterator(Function* f, Input state) +{ + return function_input_iterator< Function*, Input >(f, state); +} + +struct infinite +{ + infinite& operator++() { return *this; } + infinite& operator++(int) { return *this; } + bool operator==(infinite&) const { return false; }; + bool operator==(infinite const&) const { return false; }; +}; } // namespace iterators @@ -172,5 +159,4 @@ using iterators::infinite; } // namespace boost -#endif - +#endif // BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_