Files

142 lines
4.0 KiB
C++
Raw Permalink Normal View History

2015-09-09 13:35:03 +09:00
/*==============================================================================
2014-04-04 14:38:38 +08:00
Copyright (c) 2013 Jamboree
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)
2015-09-09 13:35:03 +09:00
==============================================================================*/
2014-04-04 14:38:38 +08:00
#ifndef BOOST_FUSION_FLATTEN_VIEW_HPP_INCLUDED
#define BOOST_FUSION_FLATTEN_VIEW_HPP_INCLUDED
2015-03-03 02:21:02 +09:00
#include <boost/fusion/support/config.hpp>
2014-04-04 14:38:38 +08:00
#include <boost/mpl/bool.hpp>
#include <boost/mpl/single_view.hpp>
#include <boost/fusion/support/detail/access.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/support/sequence_base.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/view/flatten_view/flatten_view_iterator.hpp>
2022-09-26 08:11:49 +08:00
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4512) // assignment operator could not be generated.
#endif
2014-04-04 14:38:38 +08:00
namespace boost { namespace fusion
{
struct forward_traversal_tag;
struct flatten_view_tag;
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
template <typename Sequence>
struct flatten_view
: sequence_base<flatten_view<Sequence> >
{
typedef flatten_view_tag fusion_tag;
typedef fusion_sequence_tag tag; // this gets picked up by MPL
typedef mpl::true_ is_view;
typedef forward_traversal_tag category;
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
typedef Sequence sequence_type;
typedef typename result_of::begin<Sequence>::type first_type;
typedef typename result_of::end<Sequence>::type last_type;
2015-03-03 02:21:02 +09:00
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
2014-04-04 14:38:38 +08:00
explicit flatten_view(Sequence& seq)
: seq(seq)
{}
2015-03-03 02:21:02 +09:00
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
2014-04-04 14:38:38 +08:00
first_type first() const { return fusion::begin(seq); }
2015-03-03 02:21:02 +09:00
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
2014-04-04 14:38:38 +08:00
last_type last() const { return fusion::end(seq); }
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
typename mpl::if_<traits::is_view<Sequence>, Sequence, Sequence&>::type seq;
};
}}
2022-09-26 08:11:49 +08:00
#ifdef _MSC_VER
# pragma warning(pop)
#endif
2014-04-04 14:38:38 +08:00
namespace boost { namespace fusion { namespace extension
{
template<>
struct begin_impl<flatten_view_tag>
{
template<typename Sequence>
struct apply
{
typedef typename Sequence::first_type first_type;
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
typedef typename
result_of::begin<
mpl::single_view<
typename Sequence::sequence_type> >::type
root_iterator;
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
typedef
detail::seek_descent<root_iterator, first_type>
seek_descent;
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
typedef typename seek_descent::type type;
2015-03-03 02:21:02 +09:00
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
2014-04-04 14:38:38 +08:00
static inline
type call(Sequence& seq)
{
return seek_descent::apply(root_iterator(), seq.first());
}
};
};
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
template<>
struct end_impl<flatten_view_tag>
{
template<typename Sequence>
struct apply
{
typedef typename Sequence::last_type last_type;
2015-03-03 02:21:02 +09:00
2014-04-04 14:38:38 +08:00
typedef typename
result_of::end<
mpl::single_view<
typename Sequence::sequence_type> >::type
type;
2015-03-03 02:21:02 +09:00
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
2014-04-04 14:38:38 +08:00
static inline
type call(Sequence&)
{
return type();
}
};
};
template<>
struct size_impl<flatten_view_tag>
{
template <typename Sequence>
struct apply
: result_of::distance
<
typename result_of::begin<Sequence>::type
, typename result_of::end<Sequence>::type
>
{};
};
template<>
struct empty_impl<flatten_view_tag>
{
template <typename Sequence>
struct apply
: result_of::empty<typename Sequence::sequence_type>
{};
};
}}}
#endif