forked from boostorg/fusion
fusion: merge of associative iterators/views and the new fold interface
[SVN r58618]
This commit is contained in:
136
include/boost/fusion/iterator/basic_iterator.hpp
Normal file
136
include/boost/fusion/iterator/basic_iterator.hpp
Normal file
@ -0,0 +1,136 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
|
||||
#define BOOST_FUSION_ITERATOR_BASIC_ITERATOR_HPP
|
||||
|
||||
#include <boost/fusion/iterator/iterator_facade.hpp>
|
||||
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
#include <boost/mpl/minus.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
namespace extension
|
||||
{
|
||||
template <typename>
|
||||
struct value_of_impl;
|
||||
|
||||
template <typename>
|
||||
struct deref_impl;
|
||||
|
||||
template <typename>
|
||||
struct value_of_data_impl;
|
||||
|
||||
template <typename>
|
||||
struct key_of_impl;
|
||||
|
||||
template <typename>
|
||||
struct deref_data_impl;
|
||||
}
|
||||
|
||||
template<typename Tag, typename Category, typename Seq, int Index>
|
||||
struct basic_iterator
|
||||
: iterator_facade<basic_iterator<Tag,Category,Seq,Index>, Category>
|
||||
{
|
||||
typedef mpl::int_<Index> index;
|
||||
typedef Seq seq_type;
|
||||
|
||||
template <typename It>
|
||||
struct value_of
|
||||
: extension::value_of_impl<Tag>::template apply<It>
|
||||
{};
|
||||
|
||||
template <typename It>
|
||||
struct deref
|
||||
: extension::deref_impl<Tag>::template apply<It>
|
||||
{};
|
||||
|
||||
template <typename It>
|
||||
struct value_of_data
|
||||
: extension::value_of_data_impl<Tag>::template apply<It>
|
||||
{};
|
||||
|
||||
template <typename It>
|
||||
struct key_of
|
||||
: extension::key_of_impl<Tag>::template apply<It>
|
||||
{};
|
||||
|
||||
template <typename It>
|
||||
struct deref_data
|
||||
: extension::deref_data_impl<Tag>::template apply<It>
|
||||
{};
|
||||
|
||||
template <typename It, typename N>
|
||||
struct advance
|
||||
{
|
||||
typedef
|
||||
basic_iterator<Tag, Category, Seq, Index + N::value>
|
||||
type;
|
||||
|
||||
static type
|
||||
call(It const& it)
|
||||
{
|
||||
return type(*it.seq,0);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename It>
|
||||
struct next
|
||||
: advance<It, mpl::int_<1> >
|
||||
{};
|
||||
|
||||
template <typename It>
|
||||
struct prior
|
||||
: advance<It, mpl::int_<-1> >
|
||||
{};
|
||||
|
||||
template <typename It1, typename It2>
|
||||
struct distance
|
||||
: mpl::minus<
|
||||
typename It2::index
|
||||
, typename It1::index
|
||||
>
|
||||
{};
|
||||
|
||||
template <typename It1, typename It2>
|
||||
struct equal_to
|
||||
: mpl::and_<
|
||||
is_same<
|
||||
typename remove_const<typename It1::seq_type>::type
|
||||
, typename remove_const<typename It2::seq_type>::type
|
||||
>
|
||||
, mpl::equal_to<typename It1::index,typename It2::index>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename OtherSeq>
|
||||
basic_iterator(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
|
||||
: seq(it.seq)
|
||||
{}
|
||||
|
||||
basic_iterator(Seq& seq, int)
|
||||
: seq(&seq)
|
||||
{}
|
||||
|
||||
template<typename OtherSeq>
|
||||
basic_iterator&
|
||||
operator=(basic_iterator<Tag,Category,OtherSeq,Index> const& it)
|
||||
{
|
||||
seq=it.seq;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Seq* seq;
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
49
include/boost/fusion/iterator/deref_data.hpp
Normal file
49
include/boost/fusion/iterator/deref_data.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_ITERATOR_DEREF_DATA_HPP
|
||||
#define BOOST_FUSION_ITERATOR_DEREF_DATA_HPP
|
||||
|
||||
#include <boost/fusion/support/tag_of.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct iterator_facade_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template <typename>
|
||||
struct deref_data_impl;
|
||||
|
||||
template <>
|
||||
struct deref_data_impl<iterator_facade_tag>
|
||||
{
|
||||
template <typename It>
|
||||
struct apply
|
||||
: It::template deref_data<It>
|
||||
{};
|
||||
};
|
||||
}
|
||||
|
||||
namespace result_of
|
||||
{
|
||||
template <typename It>
|
||||
struct deref_data
|
||||
: extension::deref_data_impl<typename traits::tag_of<It>::type>::
|
||||
template apply<It>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename It>
|
||||
typename result_of::deref_data<It>::type
|
||||
deref_data(It const& it)
|
||||
{
|
||||
return result_of::deref_data<It>::call(it);
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -50,8 +50,7 @@ namespace boost { namespace fusion
|
||||
template <typename First, typename Last>
|
||||
struct distance :
|
||||
distance_detail::linear_distance<First, Last>
|
||||
{
|
||||
};
|
||||
{};
|
||||
};
|
||||
}}
|
||||
|
||||
|
42
include/boost/fusion/iterator/key_of.hpp
Normal file
42
include/boost/fusion/iterator/key_of.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_ITERATOR_KEY_OF_HPP
|
||||
#define BOOST_FUSION_ITERATOR_KEY_OF_HPP
|
||||
|
||||
#include <boost/fusion/support/tag_of.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct iterator_facade_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template <typename>
|
||||
struct key_of_impl;
|
||||
|
||||
template <>
|
||||
struct key_of_impl<iterator_facade_tag>
|
||||
{
|
||||
template <typename It>
|
||||
struct apply
|
||||
: It::template key_of<It>
|
||||
{};
|
||||
};
|
||||
}
|
||||
|
||||
namespace result_of
|
||||
{
|
||||
template <typename It>
|
||||
struct key_of
|
||||
: extension::key_of_impl<typename traits::tag_of<It>::type>::
|
||||
template apply<It>
|
||||
{};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
42
include/boost/fusion/iterator/value_of_data.hpp
Normal file
42
include/boost/fusion/iterator/value_of_data.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_ITERATOR_VALUE_OF_DATA_HPP
|
||||
#define BOOST_FUSION_ITERATOR_VALUE_OF_DATA_HPP
|
||||
|
||||
#include <boost/fusion/support/tag_of.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct iterator_facade_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template <typename>
|
||||
struct value_of_data_impl;
|
||||
|
||||
template <>
|
||||
struct value_of_data_impl<iterator_facade_tag>
|
||||
{
|
||||
template <typename It>
|
||||
struct apply
|
||||
: It::template value_of_data<It>
|
||||
{};
|
||||
};
|
||||
}
|
||||
|
||||
namespace result_of
|
||||
{
|
||||
template <typename It>
|
||||
struct value_of_data
|
||||
: extension::value_of_data_impl<typename traits::tag_of<It>::type>::
|
||||
template apply<It>
|
||||
{};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user