forked from boostorg/fusion
const-correctness patch by Nathan Ridge.
[SVN r74472]
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
/*=============================================================================
|
/*=============================================================================
|
||||||
Copyright (c) 2001-2011 Joel de Guzman
|
Copyright (c) 2001-2011 Joel de Guzman
|
||||||
|
Copyright (c) 2011 Nathan Ridge
|
||||||
Copyright (c) 2006 Dan Marsden
|
Copyright (c) 2006 Dan Marsden
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
@ -17,11 +18,10 @@
|
|||||||
|
|
||||||
#include <boost/fusion/sequence/sequence_facade.hpp>
|
#include <boost/fusion/sequence/sequence_facade.hpp>
|
||||||
#include <boost/fusion/iterator/iterator_facade.hpp>
|
#include <boost/fusion/iterator/iterator_facade.hpp>
|
||||||
|
|
||||||
#include <boost/fusion/sequence/intrinsic.hpp>
|
#include <boost/fusion/sequence/intrinsic.hpp>
|
||||||
#include <boost/fusion/iterator.hpp>
|
#include <boost/fusion/iterator.hpp>
|
||||||
|
|
||||||
#include <boost/fusion/support/category_of.hpp>
|
#include <boost/fusion/support/category_of.hpp>
|
||||||
|
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||||
|
|
||||||
#include <boost/mpl/int.hpp>
|
#include <boost/mpl/int.hpp>
|
||||||
#include <boost/mpl/identity.hpp>
|
#include <boost/mpl/identity.hpp>
|
||||||
@ -40,7 +40,8 @@ namespace demo
|
|||||||
{
|
{
|
||||||
template<typename Seq, int N>
|
template<typename Seq, int N>
|
||||||
struct triple_iterator
|
struct triple_iterator
|
||||||
: fusion::iterator_facade<triple_iterator<Seq, N>, fusion::random_access_traversal_tag>
|
: fusion::iterator_facade<triple_iterator<Seq, N>,
|
||||||
|
fusion::random_access_traversal_tag>
|
||||||
{
|
{
|
||||||
typedef mpl::int_<N> index;
|
typedef mpl::int_<N> index;
|
||||||
typedef Seq sequence_type;
|
typedef Seq sequence_type;
|
||||||
@ -74,13 +75,19 @@ namespace demo
|
|||||||
template <typename Sq>
|
template <typename Sq>
|
||||||
struct deref<triple_iterator<Sq, 0> >
|
struct deref<triple_iterator<Sq, 0> >
|
||||||
{
|
{
|
||||||
typedef typename
|
typedef typename Sq::t0_type& type;
|
||||||
mpl::if_<
|
|
||||||
boost::is_const<Sq>
|
static type
|
||||||
, typename Sq::t0_type const&
|
call(triple_iterator<Sq, 0> const& iter)
|
||||||
, typename Sq::t0_type&
|
{
|
||||||
>::type
|
return iter.seq_.t0;
|
||||||
type;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Sq>
|
||||||
|
struct deref<triple_iterator<Sq, 0> const>
|
||||||
|
{
|
||||||
|
typedef typename Sq::t0_type const& type;
|
||||||
|
|
||||||
static type
|
static type
|
||||||
call(triple_iterator<Sq, 0> const& iter)
|
call(triple_iterator<Sq, 0> const& iter)
|
||||||
@ -92,13 +99,19 @@ namespace demo
|
|||||||
template <typename Sq>
|
template <typename Sq>
|
||||||
struct deref<triple_iterator<Sq, 1> >
|
struct deref<triple_iterator<Sq, 1> >
|
||||||
{
|
{
|
||||||
typedef typename
|
typedef typename Sq::t1_type& type;
|
||||||
mpl::if_<
|
|
||||||
boost::is_const<Sq>
|
static type
|
||||||
, typename Sq::t1_type const&
|
call(triple_iterator<Sq, 1> const& iter)
|
||||||
, typename Sq::t1_type&
|
{
|
||||||
>::type
|
return iter.seq_.t1;
|
||||||
type;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Sq>
|
||||||
|
struct deref<triple_iterator<Sq, 1> const>
|
||||||
|
{
|
||||||
|
typedef typename Sq::t1_type const& type;
|
||||||
|
|
||||||
static type
|
static type
|
||||||
call(triple_iterator<Sq, 1> const& iter)
|
call(triple_iterator<Sq, 1> const& iter)
|
||||||
@ -110,13 +123,19 @@ namespace demo
|
|||||||
template <typename Sq>
|
template <typename Sq>
|
||||||
struct deref<triple_iterator<Sq, 2> >
|
struct deref<triple_iterator<Sq, 2> >
|
||||||
{
|
{
|
||||||
typedef typename
|
typedef typename Sq::t2_type& type;
|
||||||
mpl::if_<
|
|
||||||
boost::is_const<Sq>
|
static type
|
||||||
, typename Sq::t2_type const&
|
call(triple_iterator<Sq, 2> const& iter)
|
||||||
, typename Sq::t2_type&
|
{
|
||||||
>::type
|
return iter.seq_.t2;
|
||||||
type;
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Sq>
|
||||||
|
struct deref<triple_iterator<Sq, 2> const>
|
||||||
|
{
|
||||||
|
typedef typename Sq::t2_type const& type;
|
||||||
|
|
||||||
static type
|
static type
|
||||||
call(triple_iterator<Sq, 2> const& iter)
|
call(triple_iterator<Sq, 2> const& iter)
|
||||||
@ -129,7 +148,8 @@ namespace demo
|
|||||||
struct next
|
struct next
|
||||||
{
|
{
|
||||||
typedef triple_iterator<
|
typedef triple_iterator<
|
||||||
typename It::sequence_type, It::index::value + 1> type;
|
typename It::sequence_type, It::index::value + 1>
|
||||||
|
type;
|
||||||
|
|
||||||
static type call(It const& it)
|
static type call(It const& it)
|
||||||
{
|
{
|
||||||
@ -141,7 +161,8 @@ namespace demo
|
|||||||
struct prior
|
struct prior
|
||||||
{
|
{
|
||||||
typedef triple_iterator<
|
typedef triple_iterator<
|
||||||
typename It::sequence_type, It::index::value - 1> type;
|
typename It::sequence_type, It::index::value - 1>
|
||||||
|
type;
|
||||||
|
|
||||||
static type call(It const& it)
|
static type call(It const& it)
|
||||||
{
|
{
|
||||||
@ -152,7 +173,9 @@ namespace demo
|
|||||||
template<typename It1, typename It2>
|
template<typename It1, typename It2>
|
||||||
struct distance
|
struct distance
|
||||||
{
|
{
|
||||||
typedef typename mpl::minus<typename It2::index, typename It1::index>::type type;
|
typedef typename mpl::minus<
|
||||||
|
typename It2::index, typename It1::index>::type
|
||||||
|
type;
|
||||||
|
|
||||||
static type call(It1 const& it1, It2 const& it2)
|
static type call(It1 const& it1, It2 const& it2)
|
||||||
{
|
{
|
||||||
@ -165,7 +188,8 @@ namespace demo
|
|||||||
{
|
{
|
||||||
typedef triple_iterator<
|
typedef triple_iterator<
|
||||||
typename It::sequence_type,
|
typename It::sequence_type,
|
||||||
It::index::value + M::value> type;
|
It::index::value + M::value>
|
||||||
|
type;
|
||||||
|
|
||||||
static type call(It const& it)
|
static type call(It const& it)
|
||||||
{
|
{
|
||||||
@ -176,7 +200,8 @@ namespace demo
|
|||||||
|
|
||||||
template<typename T0, typename T1, typename T2>
|
template<typename T0, typename T1, typename T2>
|
||||||
struct triple
|
struct triple
|
||||||
: fusion::sequence_facade<triple<T0, T1, T2>, fusion::random_access_traversal_tag>
|
: fusion::sequence_facade<triple<T0, T1, T2>,
|
||||||
|
fusion::random_access_traversal_tag>
|
||||||
{
|
{
|
||||||
triple(T0 const& t0, T1 const& t1, T2 const& t2)
|
triple(T0 const& t0, T1 const& t1, T2 const& t2)
|
||||||
: t0(t0), t1(t1), t2(t2)
|
: t0(t0), t1(t1), t2(t2)
|
||||||
@ -185,8 +210,7 @@ namespace demo
|
|||||||
template<typename Sq>
|
template<typename Sq>
|
||||||
struct begin
|
struct begin
|
||||||
{
|
{
|
||||||
typedef demo::triple_iterator<
|
typedef demo::triple_iterator<Sq, 0> type;
|
||||||
Sq, 0> type;
|
|
||||||
|
|
||||||
static type call(Sq& sq)
|
static type call(Sq& sq)
|
||||||
{
|
{
|
||||||
@ -197,8 +221,7 @@ namespace demo
|
|||||||
template<typename Sq>
|
template<typename Sq>
|
||||||
struct end
|
struct end
|
||||||
{
|
{
|
||||||
typedef demo::triple_iterator<
|
typedef demo::triple_iterator<Sq, 3> type;
|
||||||
Sq, 3> type;
|
|
||||||
|
|
||||||
static type call(Sq& sq)
|
static type call(Sq& sq)
|
||||||
{
|
{
|
||||||
@ -300,6 +323,36 @@ namespace demo
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct modifying_fold_functor
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
struct result
|
||||||
|
{
|
||||||
|
typedef bool type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool operator()(bool b, T&)
|
||||||
|
{
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nonmodifying_fold_functor
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
struct result
|
||||||
|
{
|
||||||
|
typedef bool type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool operator()(bool b, const T&)
|
||||||
|
{
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
typedef demo::triple<int, char, std::string> my_triple;
|
typedef demo::triple<int, char, std::string> my_triple;
|
||||||
@ -309,11 +362,16 @@ int main()
|
|||||||
BOOST_TEST(*fusion::prior(fusion::end(t)) == "hello");
|
BOOST_TEST(*fusion::prior(fusion::end(t)) == "hello");
|
||||||
BOOST_TEST(fusion::distance(fusion::begin(t), fusion::end(t)) == 3);
|
BOOST_TEST(fusion::distance(fusion::begin(t), fusion::end(t)) == 3);
|
||||||
BOOST_TEST(fusion::size(t) == 3);
|
BOOST_TEST(fusion::size(t) == 3);
|
||||||
BOOST_MPL_ASSERT((boost::is_same<int, fusion::result_of::value_at_c<my_triple, 0>::type>));
|
BOOST_MPL_ASSERT((boost::is_same<
|
||||||
BOOST_MPL_ASSERT((boost::is_same<char, fusion::result_of::value_at_c<my_triple, 1>::type>));
|
int, fusion::result_of::value_at_c<my_triple, 0>::type>));
|
||||||
BOOST_MPL_ASSERT((boost::is_same<std::string, fusion::result_of::value_at_c<my_triple, 2>::type>));
|
BOOST_MPL_ASSERT((boost::is_same<
|
||||||
|
char, fusion::result_of::value_at_c<my_triple, 1>::type>));
|
||||||
|
BOOST_MPL_ASSERT((boost::is_same<
|
||||||
|
std::string, fusion::result_of::value_at_c<my_triple, 2>::type>));
|
||||||
BOOST_TEST(fusion::at_c<0>(t) == 101);
|
BOOST_TEST(fusion::at_c<0>(t) == 101);
|
||||||
BOOST_TEST(fusion::at_c<1>(t) == 'a');
|
BOOST_TEST(fusion::at_c<1>(t) == 'a');
|
||||||
BOOST_TEST(fusion::at_c<2>(t) == "hello");
|
BOOST_TEST(fusion::at_c<2>(t) == "hello");
|
||||||
|
BOOST_TEST(fusion::fold(t, true, modifying_fold_functor()) == true);
|
||||||
|
BOOST_TEST(fusion::fold(t, true, nonmodifying_fold_functor()) == true);
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user