mirror of
https://github.com/boostorg/iterator.git
synced 2025-05-09 23:23:54 +00:00
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:
parent
8c2fdf6053
commit
fd1445140f
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -6,163 +6,150 @@
|
|||||||
// 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,
|
private:
|
||||||
single_pass_traversal_tag,
|
using base_type = function_input_iterator_facade_base_t< Function, Input >;
|
||||||
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() {
|
protected:
|
||||||
if (value)
|
using function_arg_type = Function&;
|
||||||
value = none;
|
|
||||||
else
|
|
||||||
(*f)();
|
|
||||||
++state;
|
|
||||||
}
|
|
||||||
|
|
||||||
typename result_of_nullary_lvalue_call<Function>::type const&
|
public:
|
||||||
dereference() const {
|
using value_type = typename base_type::value_type;
|
||||||
if (!value)
|
|
||||||
value = (*f)();
|
|
||||||
return value.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool equal(function_object_input_iterator const& other) const {
|
public:
|
||||||
return f == other.f && state == other.state;
|
function_object_input_iterator(function_arg_type f, Input state) :
|
||||||
}
|
m_f(std::addressof(f)), m_state(state)
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
Function * f;
|
typename std::add_pointer< Function >::type m_f;
|
||||||
Input state;
|
Input m_state;
|
||||||
mutable optional<typename result_of_nullary_lvalue_call<Function>::type> value;
|
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,
|
private:
|
||||||
single_pass_traversal_tag,
|
using base_type = function_input_iterator_facade_base_t< Function, Input >;
|
||||||
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() {
|
protected:
|
||||||
if (value)
|
using function_arg_type = Function;
|
||||||
value = none;
|
|
||||||
else
|
|
||||||
(*f)();
|
|
||||||
++state;
|
|
||||||
}
|
|
||||||
|
|
||||||
typename function_types::result_type<Function>::type const&
|
public:
|
||||||
dereference() const {
|
using value_type = typename base_type::value_type;
|
||||||
if (!value)
|
|
||||||
value = (*f)();
|
|
||||||
return value.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool equal(function_pointer_input_iterator const& other) const {
|
public:
|
||||||
return f == other.f && state == other.state;
|
function_pointer_input_iterator(function_arg_type f, Input state) :
|
||||||
}
|
m_f(f), m_state(state)
|
||||||
|
{}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
Function f;
|
Function m_f;
|
||||||
Input state;
|
Input m_state;
|
||||||
mutable optional<typename function_types::result_type<Function>::type> value;
|
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, class Input>
|
} // namespace detail
|
||||||
class function_input_iterator :
|
|
||||||
public std::conditional<
|
template< typename Function, typename Input >
|
||||||
function_types::is_function_pointer<Function>::value,
|
class function_input_iterator :
|
||||||
impl::function_pointer_input_iterator<Function,Input>,
|
public detail::function_input_iterator_base_t< Function, Input >
|
||||||
impl::function_object_input_iterator<Function,Input>
|
{
|
||||||
>::type
|
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<
|
if (this->m_value)
|
||||||
function_types::is_function_pointer<Function>::value,
|
this->m_value.reset();
|
||||||
impl::function_pointer_input_iterator<Function,Input>,
|
else
|
||||||
impl::function_object_input_iterator<Function,Input>
|
(*this->m_f)();
|
||||||
>::type base_type;
|
++this->m_state;
|
||||||
public:
|
|
||||||
function_input_iterator(Function& f, Input i)
|
|
||||||
: base_type(f, i) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Function, class Input>
|
|
||||||
inline function_input_iterator<Function, Input>
|
|
||||||
make_function_input_iterator(Function& f, Input state) {
|
|
||||||
typedef function_input_iterator<Function, Input> result_t;
|
|
||||||
return result_t(f, 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct infinite
|
bool equal(function_input_iterator const& other) const
|
||||||
{
|
{
|
||||||
infinite& operator++() { return *this; }
|
return this->m_f == other.m_f && this->m_state == other.m_state;
|
||||||
infinite& operator++(int) { return *this; }
|
}
|
||||||
bool operator==(infinite&) const { return false; };
|
};
|
||||||
bool operator==(infinite const&) const { return false; };
|
|
||||||
};
|
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
|
} // namespace iterators
|
||||||
|
|
||||||
@ -172,5 +159,4 @@ using iterators::infinite;
|
|||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif
|
#endif // BOOST_ITERATOR_FUNCTION_INPUT_ITERATOR_HPP_INCLUDED_
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user