Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74546 - in trunk/boost/fusion: . adapted adapted/std_tuple adapted/std_tuple/detail iterator
From: joel_at_[hidden]
Date: 2011-09-24 09:07:10


Author: djowel
Date: 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
New Revision: 74546
URL: http://svn.boost.org/trac/boost/changeset/74546

Log:
Added adapter for std::tuple (only for implementations using variadic templates)
Added:
   trunk/boost/fusion/adapted/std_tuple/
   trunk/boost/fusion/adapted/std_tuple.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/
   trunk/boost/fusion/adapted/std_tuple/detail/at_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/begin_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/category_of_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/end_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/is_sequence_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/is_view_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/size_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/detail/value_at_impl.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp (contents, props changed)
   trunk/boost/fusion/adapted/std_tuple/tag_of.hpp (contents, props changed)
Text files modified:
   trunk/boost/fusion/adapted.hpp | 6 ++++++
   trunk/boost/fusion/iterator/advance.hpp | 6 +++---
   2 files changed, 9 insertions(+), 3 deletions(-)

Modified: trunk/boost/fusion/adapted.hpp
==============================================================================
--- trunk/boost/fusion/adapted.hpp (original)
+++ trunk/boost/fusion/adapted.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/at_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/at_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/begin_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/begin_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/category_of_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/category_of_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/end_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/end_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/is_sequence_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/is_sequence_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/is_view_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/is_view_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/size_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/size_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/detail/value_at_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/detail/value_at_impl.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Added: trunk/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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
+
+

Added: trunk/boost/fusion/adapted/std_tuple/tag_of.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/adapted/std_tuple/tag_of.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -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

Modified: trunk/boost/fusion/iterator/advance.hpp
==============================================================================
--- trunk/boost/fusion/iterator/advance.hpp (original)
+++ trunk/boost/fusion/iterator/advance.hpp 2011-09-24 09:07:09 EDT (Sat, 24 Sep 2011)
@@ -1,7 +1,7 @@
 /*=============================================================================
     Copyright (c) 2001-2011 Joel de Guzman
 
- Distributed under the Boost Software License, Version 1.0. (See accompanying
+ 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_ADVANCE_09172005_1146)
@@ -18,7 +18,7 @@
 namespace boost { namespace fusion
 {
     struct random_access_traversal_tag;
-
+
     // Special tags:
     struct iterator_facade_tag; // iterator facade tag
     struct boost_array_iterator_tag; // boost::array iterator tag
@@ -59,7 +59,7 @@
         template <>
         struct advance_impl<std_pair_iterator_tag>;
     }
-
+
     namespace result_of
     {
         template <typename Iterator, int N>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk