mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-16 13:52:24 +02:00
variant as a fusion sequence
[SVN r36014]
This commit is contained in:
@ -13,5 +13,6 @@
|
|||||||
#include <boost/fusion/sequence/adapted/std_pair.hpp>
|
#include <boost/fusion/sequence/adapted/std_pair.hpp>
|
||||||
#include <boost/fusion/sequence/adapted/array.hpp>
|
#include <boost/fusion/sequence/adapted/array.hpp>
|
||||||
#include <boost/fusion/sequence/adapted/mpl.hpp>
|
#include <boost/fusion/sequence/adapted/mpl.hpp>
|
||||||
|
#include <boost/fusion/sequence/adapted/variant.hpp>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
18
include/boost/fusion/sequence/adapted/variant.hpp
Normal file
18
include/boost/fusion/sequence/adapted/variant.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2001-2006 Joel de Guzman
|
||||||
|
Copyright (c) 2005-2006 Dan Marsden
|
||||||
|
|
||||||
|
Use, modification and distribution is subject to 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_VARIANT_12112006_1614)
|
||||||
|
#define BOOST_FUSION_VARIANT_12112006_1614
|
||||||
|
|
||||||
|
#include <boost/fusion/sequence/adapted/variant/variant_iterator.hpp>
|
||||||
|
#include <boost/fusion/sequence/adapted/variant/tag_of.hpp>
|
||||||
|
#include <boost/fusion/sequence/adapted/variant/detail/size_impl.hpp>
|
||||||
|
#include <boost/fusion/sequence/adapted/variant/detail/begin_impl.hpp>
|
||||||
|
#include <boost/fusion/sequence/adapted/variant/detail/end_impl.hpp>
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,46 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2001-2006 Joel de Guzman
|
||||||
|
Copyright (c) 2005-2006 Dan Marsden
|
||||||
|
|
||||||
|
Use, modification and distribution is subject to 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_VARIANT_BEGIN_IMPL_12112006_2137)
|
||||||
|
#define BOOST_FUSION_VARIANT_BEGIN_IMPL_12112006_2137
|
||||||
|
|
||||||
|
#include <boost/mpl/begin.hpp>
|
||||||
|
|
||||||
|
namespace boost { namespace fusion {
|
||||||
|
|
||||||
|
struct variant_tag;
|
||||||
|
|
||||||
|
template<typename Seq, typename Iterator>
|
||||||
|
struct variant_iterator;
|
||||||
|
|
||||||
|
namespace extension
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
struct begin_impl;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct begin_impl<variant_tag>
|
||||||
|
{
|
||||||
|
template <typename Seq>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef variant_iterator<
|
||||||
|
Seq,
|
||||||
|
typename mpl::begin<typename Seq::types>::type> type;
|
||||||
|
|
||||||
|
static type
|
||||||
|
call(Seq& v)
|
||||||
|
{
|
||||||
|
return type(v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,46 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2001-2006 Joel de Guzman
|
||||||
|
Copyright (c) 2005-2006 Dan Marsden
|
||||||
|
|
||||||
|
Use, modification and distribution is subject to 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_VARIANT_END_IMPL_12112006_2137)
|
||||||
|
#define BOOST_FUSION_VARIANT_END_IMPL_12112006_2137
|
||||||
|
|
||||||
|
#include <boost/mpl/end.hpp>
|
||||||
|
|
||||||
|
namespace boost { namespace fusion {
|
||||||
|
|
||||||
|
struct variant_tag;
|
||||||
|
|
||||||
|
template<typename Seq, typename Iterator>
|
||||||
|
struct variant_iterator;
|
||||||
|
|
||||||
|
namespace extension
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
struct end_impl;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct end_impl<variant_tag>
|
||||||
|
{
|
||||||
|
template <typename Seq>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef variant_iterator<
|
||||||
|
Seq,
|
||||||
|
typename mpl::end<typename Seq::types>::type> type;
|
||||||
|
|
||||||
|
static type
|
||||||
|
call(Seq& v)
|
||||||
|
{
|
||||||
|
return type(v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,33 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2001-2006 Joel de Guzman
|
||||||
|
Copyright (c) 2005-2006 Dan Marsden
|
||||||
|
|
||||||
|
Use, modification and distribution is subject to 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_VARIANT_SIZE_IMPL_12112006_2115)
|
||||||
|
#define BOOST_FUSION_VARIANT_SIZE_IMPL_12112006_2115
|
||||||
|
|
||||||
|
#include <boost/mpl/size.hpp>
|
||||||
|
|
||||||
|
namespace boost { namespace fusion {
|
||||||
|
|
||||||
|
struct variant_tag;
|
||||||
|
|
||||||
|
namespace extension
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
struct size_impl;
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct size_impl<variant_tag>
|
||||||
|
{
|
||||||
|
template<typename Sequence>
|
||||||
|
struct apply : mpl::size<typename Sequence::types>
|
||||||
|
{};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
29
include/boost/fusion/sequence/adapted/variant/tag_of.hpp
Normal file
29
include/boost/fusion/sequence/adapted/variant/tag_of.hpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2001-2006 Joel de Guzman
|
||||||
|
Copyright (c) 2005-2006 Dan Marsden
|
||||||
|
|
||||||
|
Use, modification and distribution is subject to 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_VARIANT_TAG_OF_12112006_1704)
|
||||||
|
#define BOOST_FUSION_VARIANT_TAG_OF_12112006_1704
|
||||||
|
|
||||||
|
#include <boost/fusion/support/tag_of_fwd.hpp>
|
||||||
|
#include <boost/variant/variant_fwd.hpp>
|
||||||
|
|
||||||
|
namespace boost { namespace fusion
|
||||||
|
{
|
||||||
|
struct variant_tag;
|
||||||
|
|
||||||
|
namespace traits
|
||||||
|
{
|
||||||
|
template<BOOST_VARIANT_ENUM_PARAMS(typename T)>
|
||||||
|
struct tag_of<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
|
||||||
|
{
|
||||||
|
typedef variant_tag type;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,94 @@
|
|||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2001-2006 Joel de Guzman
|
||||||
|
Copyright (c) 2005-2006 Dan Marsden
|
||||||
|
|
||||||
|
Use, modification and distribution is subject to 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_VARIANT_ITERATOR_12112006_1617)
|
||||||
|
#define BOOST_FUSION_VARIANT_ITERATOR_12112006_1617
|
||||||
|
|
||||||
|
#include <boost/fusion/iterator/iterator_facade.hpp>
|
||||||
|
|
||||||
|
#include <boost/mpl/next.hpp>
|
||||||
|
#include <boost/mpl/int.hpp>
|
||||||
|
#include <boost/mpl/distance.hpp>
|
||||||
|
#include <boost/mpl/deref.hpp>
|
||||||
|
#include <boost/mpl/eval_if.hpp>
|
||||||
|
#include <boost/type_traits/is_const.hpp>
|
||||||
|
#include <boost/type_traits/add_const.hpp>
|
||||||
|
|
||||||
|
namespace boost { namespace fusion {
|
||||||
|
|
||||||
|
struct forward_traversal_tag;
|
||||||
|
|
||||||
|
template<typename Variant, typename Iterator>
|
||||||
|
struct variant_iterator
|
||||||
|
: iterator_facade<variant_iterator<Variant, Iterator>, forward_traversal_tag>
|
||||||
|
{
|
||||||
|
typedef Variant variant_type;
|
||||||
|
typedef Iterator iterator;
|
||||||
|
|
||||||
|
variant_iterator(Variant& var)
|
||||||
|
: var_(var) {}
|
||||||
|
Variant& var_;
|
||||||
|
|
||||||
|
template<typename Iterator>
|
||||||
|
struct next
|
||||||
|
{
|
||||||
|
typedef variant_iterator<
|
||||||
|
typename Iterator::variant_type,
|
||||||
|
typename mpl::next<typename Iterator::iterator>::type> type;
|
||||||
|
|
||||||
|
static type
|
||||||
|
call(Iterator const& i)
|
||||||
|
{
|
||||||
|
return type(i.var_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename I1, typename I2>
|
||||||
|
struct distance
|
||||||
|
: mpl::distance<
|
||||||
|
typename I1::iterator,
|
||||||
|
typename I2::iterator>
|
||||||
|
{
|
||||||
|
typedef typename mpl::distance<
|
||||||
|
typename I1::iterator,
|
||||||
|
typename I2::iterator>::type type;
|
||||||
|
|
||||||
|
static type call(I1 const& i1, I2 const& i2)
|
||||||
|
{
|
||||||
|
return type();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Iterator>
|
||||||
|
struct value_of
|
||||||
|
: mpl::deref<typename Iterator::iterator>
|
||||||
|
{};
|
||||||
|
|
||||||
|
template <typename Iterator>
|
||||||
|
struct deref
|
||||||
|
{
|
||||||
|
typedef typename mpl::eval_if<
|
||||||
|
is_const<typename Iterator::variant_type>,
|
||||||
|
typename add_const<typename mpl::deref<typename Iterator::iterator>::type>,
|
||||||
|
typename mpl::deref<typename Iterator::iterator>
|
||||||
|
>::type
|
||||||
|
type;
|
||||||
|
|
||||||
|
static type
|
||||||
|
call(Iterator const & it)
|
||||||
|
{
|
||||||
|
typedef typename mpl::deref<typename Iterator::iterator>::type type;
|
||||||
|
type* result = get<type>(&it.var_);
|
||||||
|
return result ? *result : type();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user