Removed usage of FunctionTypes in function_input_iterator.hpp.

This effectively removes usage of MPL in function_input_iterator.hpp and
also simplifies implementation.
This commit is contained in:
Andrey Semashev 2025-02-06 00:58:03 +03:00
parent 8c2fdf6053
commit fd1445140f
3 changed files with 116 additions and 132 deletions

View File

@ -19,7 +19,6 @@ target_link_libraries(boost_iterator
Boost::config Boost::config
Boost::core Boost::core
Boost::detail Boost::detail
Boost::function_types
Boost::fusion Boost::fusion
Boost::mpl Boost::mpl
Boost::optional Boost::optional

View File

@ -11,7 +11,6 @@ constant boost_dependencies :
/boost/config//boost_config /boost/config//boost_config
/boost/core//boost_core /boost/core//boost_core
/boost/detail//boost_detail /boost/detail//boost_detail
/boost/function_types//boost_function_types
/boost/fusion//boost_fusion /boost/fusion//boost_fusion
/boost/mpl//boost_mpl /boost/mpl//boost_mpl
/boost/optional//boost_optional /boost/optional//boost_optional

View File

@ -6,154 +6,141 @@
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
#ifndef BOOST_FUNCTION_INPUT_ITERATOR #ifndef BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_
#define BOOST_FUNCTION_INPUT_ITERATOR #define BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_
#include <type_traits>
#include <memory> #include <memory>
#include <type_traits>
#include <boost/config.hpp>
#include <boost/function_types/is_function_pointer.hpp>
#include <boost/function_types/result_type.hpp>
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/none.hpp> #include <boost/iterator/iterator_categories.hpp>
#include <boost/iterator/detail/type_traits/conjunction.hpp>
#include <boost/optional/optional.hpp> #include <boost/optional/optional.hpp>
#include <boost/utility/result_of.hpp>
namespace boost { namespace boost {
namespace iterators { namespace iterators {
template <class Function, class Input> template< typename Function, typename Input >
class function_input_iterator; class function_input_iterator;
namespace impl { namespace detail {
// Computes the return type of an lvalue-call with an empty argument, template< typename Function, typename Input >
// i.e. decltype(declval<F&>()()). F should be a nullary lvalue-callable using function_input_iterator_facade_base_t = iterator_facade<
// or function. iterators::function_input_iterator< Function, Input >,
template <class F> decltype(std::declval< Function& >()()),
struct result_of_nullary_lvalue_call single_pass_traversal_tag,
{ decltype(std::declval< Function& >()()) const&
typedef typename result_of< >;
#ifdef BOOST_RESULT_OF_USE_TR1
typename std::conditional<std::is_function<F>::value, F&, F>::type()
#else
F&()
#endif
>::type type;
};
template <class Function, class Input> template< typename Function, typename Input >
class function_object_input_iterator : class function_object_input_iterator :
public iterator_facade< public function_input_iterator_facade_base_t< Function, Input >
iterators::function_input_iterator<Function, Input>,
typename result_of_nullary_lvalue_call<Function>::type,
single_pass_traversal_tag,
typename result_of_nullary_lvalue_call<Function>::type const&
>
{ {
public:
function_object_input_iterator() {}
function_object_input_iterator(Function& f_, Input state_ = Input())
: f(std::addressof(f_)), state(state_) {}
void increment() {
if (value)
value = none;
else
(*f)();
++state;
}
typename result_of_nullary_lvalue_call<Function>::type const&
dereference() const {
if (!value)
value = (*f)();
return value.get();
}
bool equal(function_object_input_iterator const& other) const {
return f == other.f && state == other.state;
}
private: private:
Function * f; using base_type = function_input_iterator_facade_base_t< Function, Input >;
Input state;
mutable optional<typename result_of_nullary_lvalue_call<Function>::type> value; protected:
using function_arg_type = Function&;
public:
using value_type = typename base_type::value_type;
public:
function_object_input_iterator(function_arg_type f, Input state) :
m_f(std::addressof(f)), m_state(state)
{}
protected:
typename std::add_pointer< Function >::type m_f;
Input m_state;
mutable optional< value_type > m_value;
}; };
template <class Function, class Input> template< typename Function, typename Input >
class function_pointer_input_iterator : class function_pointer_input_iterator :
public iterator_facade< public function_input_iterator_facade_base_t< Function, Input >
iterators::function_input_iterator<Function, Input>,
typename function_types::result_type<Function>::type,
single_pass_traversal_tag,
typename function_types::result_type<Function>::type const&
>
{ {
public:
function_pointer_input_iterator() {}
function_pointer_input_iterator(Function& f_, Input state_ = Input())
: f(f_), state(state_) {}
void increment() {
if (value)
value = none;
else
(*f)();
++state;
}
typename function_types::result_type<Function>::type const&
dereference() const {
if (!value)
value = (*f)();
return value.get();
}
bool equal(function_pointer_input_iterator const& other) const {
return f == other.f && state == other.state;
}
private: private:
Function f; using base_type = function_input_iterator_facade_base_t< Function, Input >;
Input state;
mutable optional<typename function_types::result_type<Function>::type> value;
};
} // namespace impl protected:
using function_arg_type = Function;
template <class Function, class Input>
class function_input_iterator :
public std::conditional<
function_types::is_function_pointer<Function>::value,
impl::function_pointer_input_iterator<Function,Input>,
impl::function_object_input_iterator<Function,Input>
>::type
{
typedef typename std::conditional<
function_types::is_function_pointer<Function>::value,
impl::function_pointer_input_iterator<Function,Input>,
impl::function_object_input_iterator<Function,Input>
>::type base_type;
public: public:
function_input_iterator(Function& f, Input i) using value_type = typename base_type::value_type;
: base_type(f, i) {}
public:
function_pointer_input_iterator(function_arg_type f, Input state) :
m_f(f), m_state(state)
{}
protected:
Function m_f;
Input m_state;
mutable optional< value_type > m_value;
}; };
template <class Function, class Input> template< typename Function, typename Input >
inline function_input_iterator<Function, Input> using function_input_iterator_base_t = typename std::conditional<
make_function_input_iterator(Function& f, Input state) { detail::conjunction<
typedef function_input_iterator<Function, Input> result_t; std::is_pointer< Function >,
return result_t(f, state); 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;
} // 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()
{
if (this->m_value)
this->m_value.reset();
else
(*this->m_f)();
++this->m_state;
} }
template <class Function, class Input> reference dereference() const
inline function_input_iterator<Function*, Input> {
make_function_input_iterator(Function* f, Input state) { if (!this->m_value)
typedef function_input_iterator<Function*, Input> result_t; this->m_value = (*this->m_f)();
return result_t(f, state); return this->m_value.get();
}
bool equal(function_input_iterator const& other) const
{
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 struct infinite
@ -172,5 +159,4 @@ using iterators::infinite;
} // namespace boost } // namespace boost
#endif #endif // BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_