Fusion: added nview and friends

[SVN r56376]
This commit is contained in:
Hartmut Kaiser
2009-09-25 00:20:03 +00:00
parent b16d42a31b
commit 43645b3764
16 changed files with 721 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_ADVANCE_IMPL_SEP_24_2009_0212PM)
#define BOOST_FUSION_NVIEW_ADVANCE_IMPL_SEP_24_2009_0212PM
#include <boost/mpl/advance.hpp>
#include <boost/fusion/iterator/advance.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
template <typename Sequence, typename Pos>
struct nview_iterator;
namespace extension
{
template<typename Tag>
struct advance_impl;
template<>
struct advance_impl<nview_iterator_tag>
{
template<typename Iterator, typename Dist>
struct apply
{
typedef typename Iterator::first_type::iterator_type iterator_type;
typedef typename Iterator::sequence_type sequence_type;
typedef nview_iterator<sequence_type,
typename mpl::advance<iterator_type, Dist>::type> type;
static type
call(Iterator const& i)
{
return type(i.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,45 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_AT_IMPL_SEP_24_2009_0225PM)
#define BOOST_FUSION_NVIEW_AT_IMPL_SEP_24_2009_0225PM
#include <boost/fusion/sequence/intrinsic/at.hpp>
namespace boost { namespace fusion
{
struct nview_tag;
namespace extension
{
template<typename Tag>
struct at_impl;
template<>
struct at_impl<nview_tag>
{
template<typename Sequence, typename N>
struct apply
{
typedef typename Sequence::sequence_type sequence_type;
typedef typename Sequence::index_type index_type;
typedef typename result_of::at<index_type, N>::type index;
typedef typename result_of::at<sequence_type, index>::type type;
static type
call(Sequence& seq)
{
return fusion::at<index>(seq.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_BEGIN_IMPL_SEP_23_2009_1036PM)
#define BOOST_FUSION_NVIEW_BEGIN_IMPL_SEP_23_2009_1036PM
#include <boost/mpl/begin.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
namespace boost { namespace fusion
{
struct nview_tag;
template <typename Sequence, typename Pos>
struct nview_iterator;
namespace extension
{
template<typename Tag>
struct begin_impl;
template<>
struct begin_impl<nview_tag>
{
template<typename Sequence>
struct apply
{
typedef typename Sequence::sequence_type sequence_type;
typedef typename Sequence::index_type index_type;
typedef nview_iterator<sequence_type,
typename mpl::begin<index_type>::type> type;
static type call(Sequence& v)
{
return type(v.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,47 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_DEREF_IMPL_SEP_24_2009_0818AM)
#define BOOST_FUSION_NVIEW_DEREF_IMPL_SEP_24_2009_0818AM
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/container/vector.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
namespace extension
{
template<typename Tag>
struct deref_impl;
template<>
struct deref_impl<nview_iterator_tag>
{
template<typename Iterator>
struct apply
{
typedef typename Iterator::first_type first_type;
typedef typename Iterator::sequence_type sequence_type;
typedef typename result_of::deref<first_type>::type index;
typedef typename result_of::at<sequence_type, index>::type type;
static type call(Iterator const& i)
{
return at<index>(i.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,44 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_DISTANCE_IMPL_SEP_23_2009_0328PM)
#define BOOST_FUSION_NVIEW_DISTANCE_IMPL_SEP_23_2009_0328PM
#include <boost/fusion/iterator/distance.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
namespace extension
{
template<typename Tag>
struct distance_impl;
template<>
struct distance_impl<nview_iterator_tag>
{
template<typename First, typename Last>
struct apply
: result_of::distance<typename First::first_type, typename Last::first_type>
{
typedef typename result_of::distance<
typename First::first_type, typename Last::first_type
>::type type;
static type
call(First const& first, Last const& last)
{
return type();
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_END_IMPL_SEP_24_2009_0140PM)
#define BOOST_FUSION_NVIEW_END_IMPL_SEP_24_2009_0140PM
#include <boost/mpl/end.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
namespace boost { namespace fusion
{
struct nview_tag;
template <typename Sequence, typename Pos>
struct nview_iterator;
namespace extension
{
template <typename Tag>
struct end_impl;
// Unary Version
template <>
struct end_impl<nview_tag>
{
template <typename Sequence>
struct apply
{
typedef typename Sequence::sequence_type sequence_type;
typedef typename Sequence::index_type index_type;
typedef nview_iterator<sequence_type,
typename mpl::end<index_type>::type> type;
static type call(Sequence& v)
{
return type(v.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,33 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_ITERATOR_SEP_24_2009_0329PM)
#define BOOST_FUSION_NVIEW_ITERATOR_SEP_24_2009_0329PM
#include <boost/fusion/iterator/equal_to.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
namespace extension
{
template<typename Tag>
struct equal_to_impl;
template<>
struct equal_to_impl<nview_iterator_tag>
{
template<typename It1, typename It2>
struct apply
: result_of::equal_to<typename It1::first_type, typename It2::first_type>
{};
};
}
}}
#endif

View File

@@ -0,0 +1,48 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_NEXT_IMPL_SEP_24_2009_0116PM)
#define BOOST_FUSION_NVIEW_NEXT_IMPL_SEP_24_2009_0116PM
#include <boost/mpl/next.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
template <typename Sequence, typename Pos>
struct nview_iterator;
namespace extension
{
template <typename Tag>
struct next_impl;
template <>
struct next_impl<nview_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::first_type::iterator_type first_type;
typedef typename Iterator::sequence_type sequence_type;
typedef nview_iterator<sequence_type,
typename mpl::next<first_type>::type> type;
static type
call(Iterator const& i)
{
return type(i.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,66 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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_PP_IS_ITERATING
#if !defined(BOOST_FUSION_NVIEW_IMPL_SEP_23_2009_1017PM)
#define BOOST_FUSION_NVIEW_IMPL_SEP_23_2009_1017PM
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/iterate.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
#define BOOST_PP_ITERATION_PARAMS_1 \
(3, (1, FUSION_MAX_VECTOR_SIZE, \
"boost/fusion/view/nview/detail/nview_impl.hpp")) \
/**/
#include BOOST_PP_ITERATE()
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace fusion { namespace result_of
{
template <typename Sequence
, BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(FUSION_MAX_VECTOR_SIZE, int I, -1)>
struct as_nview
{
typedef mpl::vector_c<
int, BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, I)
> index_type;
typedef nview<Sequence, index_type> type;
};
}}}
#endif
///////////////////////////////////////////////////////////////////////////////
// Preprocessor vertical repetition code
///////////////////////////////////////////////////////////////////////////////
#else // defined(BOOST_PP_IS_ITERATING)
#define N BOOST_PP_ITERATION()
namespace boost { namespace fusion
{
template<BOOST_PP_ENUM_PARAMS(N, int I), typename Sequence>
inline nview<Sequence, mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> >
as_nview(Sequence& s)
{
typedef mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> index_type;
return nview<Sequence, index_type>(s);
}
}}
#undef N
#endif

View File

@@ -0,0 +1,48 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_PRIOR_IMPL_SEP_24_2009_0142PM)
#define BOOST_FUSION_NVIEW_PRIOR_IMPL_SEP_24_2009_0142PM
#include <boost/mpl/prior.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
template <typename Sequence, typename Pos>
struct nview_iterator;
namespace extension
{
template <typename Tag>
struct prior_impl;
template <>
struct prior_impl<nview_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::first_type::iterator_type first_type;
typedef typename Iterator::sequence_type sequence_type;
typedef nview_iterator<sequence_type,
typename mpl::prior<first_type>::type> type;
static type
call(Iterator const& i)
{
return type(i.seq);
}
};
};
}
}}
#endif

View File

@@ -0,0 +1,39 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_NVIEW_VALUE_AT_IMPL_SEP_24_2009_0234PM)
#define BOOST_FUSION_NVIEW_VALUE_AT_IMPL_SEP_24_2009_0234PM
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
namespace boost { namespace fusion
{
struct nview_tag;
namespace extension
{
template<typename Tag>
struct value_at_impl;
template<>
struct value_at_impl<nview_tag>
{
template<typename Sequence, typename N>
struct apply
{
typedef typename Sequence::sequence_type sequence_type;
typedef typename Sequence::index_type index_type;
typedef typename result_of::at<index_type, N>::type index;
typedef typename result_of::at<sequence_type, index>::type type;
};
};
}
}}
#endif

View File

@@ -0,0 +1,43 @@
/*=============================================================================
Copyright (c) 2009 Hartmut Kaiser
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)
==============================================================================*/
#if !defined(BOOST_FUSION_VALUE_OF_PRIOR_IMPL_SEP_24_2009_0158PM)
#define BOOST_FUSION_VALUE_OF_PRIOR_IMPL_SEP_24_2009_0158PM
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/container/vector.hpp>
namespace boost { namespace fusion
{
struct nview_iterator_tag;
template <typename Sequence, typename Pos>
struct nview_iterator;
namespace extension
{
template <typename Tag>
struct value_of_impl;
template <>
struct value_of_impl<nview_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::first_type first_type;
typedef typename Iterator::sequence_type sequence_type;
typedef typename result_of::deref<first_type>::type index;
typedef typename result_of::at<sequence_type, index>::type type;
};
};
}
}}
#endif