Compare commits

..

1 Commits

Author SHA1 Message Date
a9b594c925 v2, v3, integration branch
[SVN r62649]
2010-06-09 11:34:33 +00:00
9 changed files with 83 additions and 175 deletions

View File

@ -13,7 +13,6 @@ boostbook standalone
:
iterator
:
<xsl:param>boost.root=../../../..
<xsl:param>toc.max.depth=3
<xsl:param>toc.section.depth=3
<xsl:param>chunk.section.depth=4

View File

@ -7,29 +7,23 @@
#ifndef BOOST_FUNCTION_INPUT_ITERATOR
#define BOOST_FUNCTION_INPUT_ITERATOR
#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>
namespace boost {
namespace impl {
template <class Function, class Input>
template <class Function, class Input>
class function_input_iterator
: public iterator_facade<
: public iterator_facade<
function_input_iterator<Function, Input>,
typename Function::result_type,
single_pass_traversal_tag,
typename Function::result_type const &
>
{
{
public:
function_input_iterator() {}
function_input_iterator(Function & f_, Input state_ = Input())
: f(&f_), state(state_), value((*f)()) {}
function_input_iterator(Function * f_, Input state_ = Input())
: f(f_), state(state_), value((*f)()) {}
void increment() {
value = (*f)();
@ -37,8 +31,8 @@ namespace boost {
}
typename Function::result_type const &
dereference() const {
return value;
dereference() const {
return value;
}
bool equal(function_input_iterator const & other) const {
@ -49,93 +43,13 @@ namespace boost {
Function * f;
Input state;
typename Function::result_type value;
};
template <class Function, class Input>
class function_pointer_input_iterator
: public iterator_facade<
function_pointer_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_), value((*f)())
{}
void increment() {
value = (*f)();
++state;
}
typename function_types::result_type<Function>::type const &
dereference() const {
return value;
}
bool equal(function_pointer_input_iterator const & other) const {
return f == other.f && state == other.state;
}
private:
Function f;
Input state;
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>
class function_input_iterator
: 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
>::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
>::type base_type;
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>
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);
make_function_input_iterator(Function & f, Input state) {
typedef function_input_iterator<Function, Input> result_t;
return result_t(&f, state);
}
struct infinite {

View File

@ -24,9 +24,15 @@
#ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY
# include <boost/type_traits/remove_reference.hpp>
# if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x610))
# include <boost/type_traits/add_reference.hpp>
# endif
#else
# include <boost/type_traits/add_reference.hpp>
#endif
#include <boost/type_traits/add_reference.hpp>
#include <boost/iterator/detail/config_def.hpp>
#include <boost/iterator/iterator_traits.hpp>

View File

@ -324,7 +324,7 @@ namespace boost
static type make(Reference x)
{
return boost::implicit_cast<type>(&x);
return implicit_cast<type>(&x);
}
};

View File

@ -42,11 +42,13 @@ namespace boost
struct transform_iterator_base
{
private:
typedef typename std::iterator_traits<Iterator>::reference Arg1;
// By default, dereferencing the iterator yields the same as
// the function.
typedef typename ia_dflt_help<
Reference
, result_of<UnaryFunc(typename std::iterator_traits<Iterator>::reference)>
, result_of<UnaryFunc(typename std::iterator_traits<Iterator>::value_type)>
>::type reference;
// To get the default for Value: remove any reference on the

View File

@ -0,0 +1,59 @@
// (C) Copyright David Abrahams and Jeremy Siek 2000-2001.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Revision History:
// 04 Jan 2001 Factored counting_iterator stuff into
// boost/counting_iterator.hpp (David Abrahams)
#ifndef BOOST_INTEGER_RANGE_HPP_
#define BOOST_INTEGER_RANGE_HPP_
#include <boost/config.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <algorithm>
namespace boost {
//=============================================================================
// Counting Iterator and Integer Range Class
template <class IntegerType>
struct integer_range {
typedef counting_iterator<IntegerType> iterator;
typedef iterator const_iterator;
typedef IntegerType value_type;
typedef std::ptrdiff_t difference_type;
typedef IntegerType reference;
typedef IntegerType const_reference;
typedef const IntegerType* pointer;
typedef const IntegerType* const_pointer;
typedef IntegerType size_type;
integer_range(IntegerType start, IntegerType finish)
: m_start(start), m_finish(finish) { }
iterator begin() const { return iterator(m_start); }
iterator end() const { return iterator(m_finish); }
size_type size() const { return m_finish - m_start; }
bool empty() const { return m_finish == m_start; }
void swap(integer_range& x) {
std::swap(m_start, x.m_start);
std::swap(m_finish, x.m_finish);
}
protected:
IntegerType m_start, m_finish;
};
template <class IntegerType>
inline integer_range<IntegerType>
make_integer_range(IntegerType first, IntegerType last)
{
return integer_range<IntegerType>(first, last);
}
} // namespace boost
#endif // BOOST_INTEGER_RANGE_HPP_

View File

@ -43,6 +43,5 @@ test-suite iterator
[ run iterator_traits_test.cpp ]
[ run permutation_iterator_test.cpp : : : # <stlport-iostream>on
]
[ run function_input_iterator_test.cpp ]
;

View File

@ -1,70 +0,0 @@
// Copyright 2010 (c) Dean Michael Berris
// Distributed under the Boost Software License Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/iterator/function_input_iterator.hpp>
#include <vector>
#include <iterator>
#include <cassert>
#include <algorithm>
#include <iostream>
struct ones {
typedef int result_type;
result_type operator() () {
return 1;
}
};
int ones_function () {
return 1;
}
using namespace std;
int main(int argc, char * argv[])
{
// test the iterator with function objects
ones ones_generator;
vector<int> values(10);
generate(values.begin(), values.end(), ones());
vector<int> generated;
copy(
boost::make_function_input_iterator(ones_generator, 0),
boost::make_function_input_iterator(ones_generator, 10),
back_inserter(generated)
);
assert(values.size() == generated.size());
assert(equal(values.begin(), values.end(), generated.begin()));
cout << "function iterator test with function objects successful." << endl;
// test the iterator with normal functions
vector<int>().swap(generated);
copy(
boost::make_function_input_iterator(&ones_function, 0),
boost::make_function_input_iterator(&ones_function, 10),
back_inserter(generated)
);
assert(values.size() == generated.size());
assert(equal(values.begin(), values.end(), generated.begin()));
cout << "function iterator test with pointer to function successful." << endl;
// test the iterator with a reference to a function
vector<int>().swap(generated);
copy(
boost::make_function_input_iterator(ones_function, 0),
boost::make_function_input_iterator(ones_function, 10),
back_inserter(generated)
);
assert(values.size() == generated.size());
assert(equal(values.begin(), values.end(), generated.begin()));
cout << "function iterator test with reference to function successful." << endl;
return 0;
}

View File

@ -106,12 +106,11 @@ struct polymorphic_mult_functor
{
//Implement result_of protocol
template <class FArgs> struct result;
template <class F, class T> struct result<F(T )> {typedef T type;};
template <class F, class T> struct result<F(T& )> {typedef T type;};
template <class F, class T> struct result<F(const T&)> {typedef T type;};
template <class F, class T> struct result<F(T)> {typedef T type;};
template <class T>
T operator()(const T& _arg) const {return _arg*2;}
typename result<polymorphic_mult_functor(T)>::type
operator()(const T& _arg) const {return _arg*2;}
};
int