Merge pull request #32 from morinmorin/clean_up_function_input_iterator

Clean up function_input_iterator
This commit is contained in:
Andrey Semashev 2017-09-07 18:46:07 +03:00 committed by GitHub
commit e61592c553
2 changed files with 8 additions and 27 deletions

View File

@ -11,9 +11,9 @@
#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>
@ -30,15 +30,15 @@ namespace iterators {
class function_input_iterator
: public iterator_facade<
function_input_iterator<Function, Input>,
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type,
typename result_of<Function ()>::type,
single_pass_traversal_tag,
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
typename result_of<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 +48,7 @@ namespace iterators {
++state;
}
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
typename result_of<Function ()>::type const &
dereference() const {
return (value ? value : value = (*f)()).get();
}
@ -60,7 +60,7 @@ namespace iterators {
private:
Function * f;
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>
@ -100,16 +100,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 +107,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)

View File

@ -6,7 +6,6 @@
#include <cstddef>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>