mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-23 17:37:15 +02:00
Merge branch 'develop'
This commit is contained in:
@ -115,8 +115,8 @@ __ iterator_facade.pdf
|
|||||||
__ iterator_adaptor.pdf
|
__ iterator_adaptor.pdf
|
||||||
|
|
||||||
Both |facade| and |adaptor| as well as many of the `specialized
|
Both |facade| and |adaptor| as well as many of the `specialized
|
||||||
adaptors`_ mentioned below have been proposed for standardization,
|
adaptors`_ mentioned below have been proposed for standardization;
|
||||||
and accepted into the first C++ technical report; see our
|
see our
|
||||||
|
|
||||||
`Standard Proposal For Iterator Facade and Adaptor`__ (PDF__)
|
`Standard Proposal For Iterator Facade and Adaptor`__ (PDF__)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#ifndef BOOST_FUNCTION_INPUT_ITERATOR
|
#ifndef BOOST_FUNCTION_INPUT_ITERATOR
|
||||||
#define BOOST_FUNCTION_INPUT_ITERATOR
|
#define BOOST_FUNCTION_INPUT_ITERATOR
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.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>
|
||||||
@ -17,6 +18,7 @@
|
|||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
#include <boost/none.hpp>
|
#include <boost/none.hpp>
|
||||||
#include <boost/optional/optional.hpp>
|
#include <boost/optional/optional.hpp>
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
@ -28,9 +30,9 @@ 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>,
|
||||||
typename Function::result_type,
|
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type,
|
||||||
single_pass_traversal_tag,
|
single_pass_traversal_tag,
|
||||||
typename Function::result_type const &
|
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -46,7 +48,7 @@ namespace iterators {
|
|||||||
++state;
|
++state;
|
||||||
}
|
}
|
||||||
|
|
||||||
typename Function::result_type const &
|
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
|
||||||
dereference() const {
|
dereference() const {
|
||||||
return (value ? value : value = (*f)()).get();
|
return (value ? value : value = (*f)()).get();
|
||||||
}
|
}
|
||||||
@ -58,7 +60,7 @@ namespace iterators {
|
|||||||
private:
|
private:
|
||||||
Function * f;
|
Function * f;
|
||||||
Input state;
|
Input state;
|
||||||
mutable optional<typename Function::result_type> value;
|
mutable optional<BOOST_DEDUCED_TYPENAME result_of<Function ()>::type> value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Function, class Input>
|
template <class Function, class Input>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
#include <boost/iterator/function_input_iterator.hpp>
|
#include <boost/iterator/function_input_iterator.hpp>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -96,6 +97,23 @@ int main(int argc, char * argv[])
|
|||||||
assert(generated[i] == 42 + i);
|
assert(generated[i] == 42 + i);
|
||||||
cout << "function iterator test with stateful function object successful." << endl;
|
cout << "function iterator test with stateful function object successful." << endl;
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
|
||||||
|
// test the iterator with lambda expressions
|
||||||
|
int num = 42;
|
||||||
|
auto lambda_generator = [&num] { return num++; };
|
||||||
|
vector<int>().swap(generated);
|
||||||
|
copy(
|
||||||
|
boost::make_function_input_iterator(lambda_generator, 0),
|
||||||
|
boost::make_function_input_iterator(lambda_generator, 10),
|
||||||
|
back_inserter(generated)
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(generated.size() == 10);
|
||||||
|
for(std::size_t i = 0; i != 10; ++i)
|
||||||
|
assert(generated[i] == 42 + i);
|
||||||
|
cout << "function iterator test with lambda expressions successful." << endl;
|
||||||
|
#endif // BOOST_NO_CXX11_LAMBDAS
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,37 +33,6 @@
|
|||||||
|
|
||||||
using boost::dummyT;
|
using boost::dummyT;
|
||||||
|
|
||||||
struct mult_functor {
|
|
||||||
typedef int result_type;
|
|
||||||
typedef int argument_type;
|
|
||||||
// Functors used with transform_iterator must be
|
|
||||||
// DefaultConstructible, as the transform_iterator must be
|
|
||||||
// DefaultConstructible to satisfy the requirements for
|
|
||||||
// TrivialIterator.
|
|
||||||
mult_functor() { }
|
|
||||||
mult_functor(int aa) : a(aa) { }
|
|
||||||
int operator()(int b) const { return a * b; }
|
|
||||||
int a;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Pair>
|
|
||||||
struct select1st_
|
|
||||||
: public std::unary_function<Pair, typename Pair::first_type>
|
|
||||||
{
|
|
||||||
const typename Pair::first_type& operator()(const Pair& x) const {
|
|
||||||
return x.first;
|
|
||||||
}
|
|
||||||
typename Pair::first_type& operator()(Pair& x) const {
|
|
||||||
return x.first;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct one_or_four {
|
|
||||||
bool operator()(dummyT x) const {
|
|
||||||
return x.foo() == 1 || x.foo() == 4;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::deque<int> storage;
|
typedef std::deque<int> storage;
|
||||||
typedef std::deque<int*> pointer_deque;
|
typedef std::deque<int*> pointer_deque;
|
||||||
typedef std::set<storage::iterator> iterator_set;
|
typedef std::set<storage::iterator> iterator_set;
|
||||||
|
@ -56,12 +56,24 @@ int main()
|
|||||||
STATIC_ASSERT_SAME(boost::pointee<X*>::type, X);
|
STATIC_ASSERT_SAME(boost::pointee<X*>::type, X);
|
||||||
STATIC_ASSERT_SAME(boost::pointee<X const*>::type, X const);
|
STATIC_ASSERT_SAME(boost::pointee<X const*>::type, X const);
|
||||||
|
|
||||||
|
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||||
|
|
||||||
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int> >::type, int);
|
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int> >::type, int);
|
||||||
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X> >::type, X);
|
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X> >::type, X);
|
||||||
|
|
||||||
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int const> >::type, int const);
|
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int const> >::type, int const);
|
||||||
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X const> >::type, X const);
|
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X const> >::type, X const);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<int> >::type, int);
|
||||||
|
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<X> >::type, X);
|
||||||
|
|
||||||
|
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<int const> >::type, int const);
|
||||||
|
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<X const> >::type, X const);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
STATIC_ASSERT_SAME(boost::pointee<std::list<int>::iterator >::type, int);
|
STATIC_ASSERT_SAME(boost::pointee<std::list<int>::iterator >::type, int);
|
||||||
STATIC_ASSERT_SAME(boost::pointee<std::list<X>::iterator >::type, X);
|
STATIC_ASSERT_SAME(boost::pointee<std::list<X>::iterator >::type, X);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user