mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-25 10:27:19 +02:00
Merge pull request #32 from morinmorin/clean_up_function_input_iterator
Clean up function_input_iterator
This commit is contained in:
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/core/addressof.hpp>
|
||||||
#include <boost/mpl/if.hpp>
|
#include <boost/mpl/if.hpp>
|
||||||
#include <boost/function_types/is_function_pointer.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/function_types/result_type.hpp>
|
||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
#include <boost/none.hpp>
|
#include <boost/none.hpp>
|
||||||
@ -30,15 +30,15 @@ namespace iterators {
|
|||||||
class function_input_iterator
|
class function_input_iterator
|
||||||
: public iterator_facade<
|
: public iterator_facade<
|
||||||
function_input_iterator<Function, Input>,
|
function_input_iterator<Function, Input>,
|
||||||
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type,
|
typename result_of<Function ()>::type,
|
||||||
single_pass_traversal_tag,
|
single_pass_traversal_tag,
|
||||||
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
|
typename result_of<Function ()>::type const &
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
function_input_iterator() {}
|
function_input_iterator() {}
|
||||||
function_input_iterator(Function & f_, Input state_ = Input())
|
function_input_iterator(Function & f_, Input state_ = Input())
|
||||||
: f(&f_), state(state_) {}
|
: f(boost::addressof(f_)), state(state_) {}
|
||||||
|
|
||||||
void increment() {
|
void increment() {
|
||||||
if(value)
|
if(value)
|
||||||
@ -48,7 +48,7 @@ namespace iterators {
|
|||||||
++state;
|
++state;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
|
typename result_of<Function ()>::type const &
|
||||||
dereference() const {
|
dereference() const {
|
||||||
return (value ? value : value = (*f)()).get();
|
return (value ? value : value = (*f)()).get();
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ namespace iterators {
|
|||||||
private:
|
private:
|
||||||
Function * f;
|
Function * f;
|
||||||
Input state;
|
Input state;
|
||||||
mutable optional<BOOST_DEDUCED_TYPENAME result_of<Function ()>::type> value;
|
mutable optional<typename result_of<Function ()>::type> value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Function, class Input>
|
template <class Function, class Input>
|
||||||
@ -100,16 +100,6 @@ namespace iterators {
|
|||||||
mutable optional<typename function_types::result_type<Function>::type> value;
|
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
|
} // namespace impl
|
||||||
|
|
||||||
template <class Function, class Input>
|
template <class Function, class Input>
|
||||||
@ -117,21 +107,13 @@ namespace iterators {
|
|||||||
: public mpl::if_<
|
: public mpl::if_<
|
||||||
function_types::is_function_pointer<Function>,
|
function_types::is_function_pointer<Function>,
|
||||||
impl::function_pointer_input_iterator<Function,Input>,
|
impl::function_pointer_input_iterator<Function,Input>,
|
||||||
typename mpl::if_<
|
impl::function_input_iterator<Function,Input>
|
||||||
function_types::is_function_reference<Function>,
|
|
||||||
impl::function_reference_input_iterator<Function,Input>,
|
|
||||||
impl::function_input_iterator<Function,Input>
|
|
||||||
>::type
|
|
||||||
>::type
|
>::type
|
||||||
{
|
{
|
||||||
typedef typename mpl::if_<
|
typedef typename mpl::if_<
|
||||||
function_types::is_function_pointer<Function>,
|
function_types::is_function_pointer<Function>,
|
||||||
impl::function_pointer_input_iterator<Function,Input>,
|
impl::function_pointer_input_iterator<Function,Input>,
|
||||||
typename mpl::if_<
|
impl::function_input_iterator<Function,Input>
|
||||||
function_types::is_function_reference<Function>,
|
|
||||||
impl::function_reference_input_iterator<Function,Input>,
|
|
||||||
impl::function_input_iterator<Function,Input>
|
|
||||||
>::type
|
|
||||||
>::type base_type;
|
>::type base_type;
|
||||||
public:
|
public:
|
||||||
function_input_iterator(Function & f, Input i)
|
function_input_iterator(Function & f, Input i)
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user