mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-29 12:07:36 +02:00
Added adapter for std::tuple (only for implementations using variadic templates)
[SVN r74546]
This commit is contained in:
@ -16,4 +16,10 @@
|
||||
#include <boost/fusion/adapted/std_pair.hpp>
|
||||
#include <boost/fusion/adapted/struct.hpp>
|
||||
|
||||
// The std_tuple_iterator adaptor only supports implementations
|
||||
// using variadic templates
|
||||
#if !defined(BOOST_NO_VARIADIC_TEMPLATES)
|
||||
#include <boost/fusion/adapted/std_tuple.hpp>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
21
include/boost/fusion/adapted/std_tuple.hpp
Normal file
21
include/boost/fusion/adapted/std_tuple.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_BOOST_TUPLE_09242011_1744)
|
||||
#define BOOST_FUSION_BOOST_TUPLE_09242011_1744
|
||||
|
||||
#include <boost/fusion/adapted/std_tuple/detail/is_view_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/is_sequence_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/category_of_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/begin_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/end_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/size_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/at_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/detail/value_at_impl.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp>
|
||||
#include <boost/fusion/adapted/std_tuple/tag_of.hpp>
|
||||
|
||||
#endif
|
52
include/boost/fusion/adapted/std_tuple/detail/at_impl.hpp
Normal file
52
include/boost/fusion/adapted/std_tuple/detail/at_impl.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_AT_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_AT_IMPL_09242011_1744
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/fusion/support/detail/access.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct at_impl;
|
||||
|
||||
template <>
|
||||
struct at_impl<std_tuple_tag>
|
||||
{
|
||||
template <typename Sequence, typename N>
|
||||
struct apply
|
||||
{
|
||||
typedef typename remove_const<Sequence>::type seq_type;
|
||||
typedef std::tuple_element<N::value, seq_type> element;
|
||||
|
||||
typedef typename
|
||||
mpl::eval_if<
|
||||
is_const<Sequence>
|
||||
, fusion::detail::cref_result<element>
|
||||
, fusion::detail::ref_result<element>
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type
|
||||
call(Sequence& seq)
|
||||
{
|
||||
return std::get<N::value>(seq);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
39
include/boost/fusion/adapted/std_tuple/detail/begin_impl.hpp
Normal file
39
include/boost/fusion/adapted/std_tuple/detail/begin_impl.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_BEGIN_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_BEGIN_IMPL_09242011_1744
|
||||
|
||||
#include <boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct begin_impl;
|
||||
|
||||
template <>
|
||||
struct begin_impl<std_tuple_tag>
|
||||
{
|
||||
template <typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef std_tuple_iterator<Sequence, 0> type;
|
||||
|
||||
static type
|
||||
call(Sequence& v)
|
||||
{
|
||||
return type(v);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,32 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_CATEGORY_OF_IMPL_09272006_0726)
|
||||
#define BOOST_FUSION_CATEGORY_OF_IMPL_09272006_0726
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
struct random_access_traversal_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct category_of_impl;
|
||||
|
||||
template<>
|
||||
struct category_of_impl<std_tuple_tag>
|
||||
{
|
||||
template<typename T>
|
||||
struct apply
|
||||
{
|
||||
typedef random_access_traversal_tag type;
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
43
include/boost/fusion/adapted/std_tuple/detail/end_impl.hpp
Normal file
43
include/boost/fusion/adapted/std_tuple/detail/end_impl.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_END_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_END_IMPL_09242011_1744
|
||||
|
||||
#include <boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <tuple>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct end_impl;
|
||||
|
||||
template <>
|
||||
struct end_impl<std_tuple_tag>
|
||||
{
|
||||
template <typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
typedef typename remove_const<Sequence>::type seq_type;
|
||||
static int const size = std::tuple_size<seq_type>::value;
|
||||
typedef std_tuple_iterator<Sequence, size> type;
|
||||
|
||||
static type
|
||||
call(Sequence& v)
|
||||
{
|
||||
return type(v);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_IS_SEQUENCE_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_IS_SEQUENCE_IMPL_09242011_1744
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct is_sequence_impl;
|
||||
|
||||
template<>
|
||||
struct is_sequence_impl<std_tuple_tag>
|
||||
{
|
||||
template<typename Sequence>
|
||||
struct apply : mpl::true_ {};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_IS_VIEW_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_IS_VIEW_IMPL_09242011_1744
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct is_view_impl;
|
||||
|
||||
template<>
|
||||
struct is_view_impl<std_tuple_tag>
|
||||
{
|
||||
template<typename T>
|
||||
struct apply : mpl::false_ {};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
31
include/boost/fusion/adapted/std_tuple/detail/size_impl.hpp
Normal file
31
include/boost/fusion/adapted/std_tuple/detail/size_impl.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_SIZE_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_SIZE_IMPL_09242011_1744
|
||||
|
||||
#include <tuple>
|
||||
#include <boost/mpl/int.hpp>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct size_impl;
|
||||
|
||||
template <>
|
||||
struct size_impl<std_tuple_tag>
|
||||
{
|
||||
template <typename Sequence>
|
||||
struct apply : mpl::int_<std::tuple_size<Sequence>::value> {};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_AT_IMPL_09242011_1744)
|
||||
#define BOOST_FUSION_VALUE_AT_IMPL_09242011_1744
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename T>
|
||||
struct value_at_impl;
|
||||
|
||||
template <>
|
||||
struct value_at_impl<std_tuple_tag>
|
||||
{
|
||||
template <typename Sequence, typename N>
|
||||
struct apply : std::tuple_element<N::value, Sequence> {};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
107
include/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp
Normal file
107
include/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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(FUSION_STD_TUPLE_ITERATOR_09112011_1905)
|
||||
#define FUSION_STD_TUPLE_ITERATOR_09112011_1905
|
||||
|
||||
#include <boost/fusion/iterator/iterator_facade.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/fusion/support/detail/access.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct random_access_traversal_tag;
|
||||
|
||||
template <typename Tuple, int Index>
|
||||
struct std_tuple_iterator_identity;
|
||||
|
||||
template <typename Tuple, int Index>
|
||||
struct std_tuple_iterator
|
||||
: iterator_facade<
|
||||
std_tuple_iterator<Tuple, Index>
|
||||
, random_access_traversal_tag>
|
||||
{
|
||||
typedef Tuple tuple_type;
|
||||
static int const index = Index;
|
||||
typedef std_tuple_iterator_identity<
|
||||
typename add_const<Tuple>::type, Index>
|
||||
identity;
|
||||
|
||||
explicit std_tuple_iterator(Tuple& tuple)
|
||||
: tuple(tuple) {}
|
||||
|
||||
Tuple& tuple;
|
||||
|
||||
template <typename Iterator>
|
||||
struct value_of
|
||||
: std::tuple_element<Iterator::index,
|
||||
typename remove_const<typename Iterator::tuple_type>::type> {};
|
||||
|
||||
template <typename Iterator>
|
||||
struct deref
|
||||
{
|
||||
typedef value_of<Iterator> element;
|
||||
typedef typename
|
||||
mpl::eval_if<
|
||||
is_const<typename Iterator::tuple_type>
|
||||
, fusion::detail::cref_result<element>
|
||||
, fusion::detail::ref_result<element>
|
||||
>::type
|
||||
type;
|
||||
|
||||
static type
|
||||
call(Iterator const& iter)
|
||||
{
|
||||
return std::get<Index>(iter.tuple);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename N>
|
||||
struct advance
|
||||
{
|
||||
static int const index = Iterator::index;
|
||||
typedef typename Iterator::tuple_type tuple_type;
|
||||
typedef std_tuple_iterator<tuple_type, index+N::value> type;
|
||||
|
||||
static type
|
||||
call(Iterator const& i)
|
||||
{
|
||||
return type(i.tuple);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
struct next : advance<Iterator, mpl::int_<1>> {};
|
||||
|
||||
template <typename Iterator>
|
||||
struct prior : advance<Iterator, mpl::int_<-1>> {};
|
||||
|
||||
template <typename I1, typename I2>
|
||||
struct equal_to
|
||||
: is_same<typename I1::identity, typename I2::identity> {};
|
||||
|
||||
template <typename First, typename Last>
|
||||
struct distance
|
||||
{
|
||||
typedef mpl::int_<Last::index-First::index> type;
|
||||
|
||||
static type
|
||||
call(First const&, Last const&)
|
||||
{
|
||||
return type();
|
||||
}
|
||||
};
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
52
include/boost/fusion/adapted/std_tuple/tag_of.hpp
Normal file
52
include/boost/fusion/adapted/std_tuple/tag_of.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
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_TAG_OF_09112011_1842)
|
||||
#define BOOST_FUSION_TAG_OF_09112011_1842
|
||||
|
||||
#include <tuple>
|
||||
#include <boost/fusion/support/tag_of_fwd.hpp>
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <typename... Elements>
|
||||
class tuple;
|
||||
}
|
||||
|
||||
namespace boost { namespace fusion
|
||||
{
|
||||
struct std_tuple_tag;
|
||||
struct fusion_sequence_tag;
|
||||
|
||||
namespace traits
|
||||
{
|
||||
template <typename... Elements>
|
||||
struct tag_of<std::tuple<Elements...>>
|
||||
{
|
||||
typedef std_tuple_tag type;
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
namespace boost { namespace mpl
|
||||
{
|
||||
template<typename>
|
||||
struct sequence_tag;
|
||||
|
||||
template <typename... Elements>
|
||||
struct sequence_tag<std::tuple<Elements...>>
|
||||
{
|
||||
typedef fusion::fusion_sequence_tag type;
|
||||
};
|
||||
|
||||
template <typename... Elements>
|
||||
struct sequence_tag<std::tuple<Elements...> const>
|
||||
{
|
||||
typedef fusion::fusion_sequence_tag type;
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user