Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82721 - in trunk/boost/fusion/container: deque map map/detail
From: joel_at_[hidden]
Date: 2013-02-06 20:25:28


Author: djowel
Date: 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
New Revision: 82721
URL: http://svn.boost.org/trac/boost/changeset/82721

Log:
added as_map
fixed bug: wrong iterator category for map_iterator
Added:
   trunk/boost/fusion/container/map/detail/build_map.hpp (contents, props changed)
   trunk/boost/fusion/container/map/detail/map_index.hpp (contents, props changed)
Text files modified:
   trunk/boost/fusion/container/deque/convert.hpp | 4 +-
   trunk/boost/fusion/container/map/convert.hpp | 47 +++++++++++++++++++++++++++++++++++++++
   trunk/boost/fusion/container/map/detail/at_impl.hpp | 10 +++++---
   trunk/boost/fusion/container/map/map.hpp | 6 +++++
   trunk/boost/fusion/container/map/map_iterator.hpp | 20 +---------------
   5 files changed, 62 insertions(+), 25 deletions(-)

Modified: trunk/boost/fusion/container/deque/convert.hpp
==============================================================================
--- trunk/boost/fusion/container/deque/convert.hpp (original)
+++ trunk/boost/fusion/container/deque/convert.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -41,7 +41,7 @@
     inline typename result_of::as_deque<Sequence>::type
     as_deque(Sequence& seq)
     {
- typedef typename result_of::as_deque<Sequence>::gen gen;
+ typedef result_of::as_deque<Sequence> gen;
         return gen::call(fusion::begin(seq), fusion::end(seq));
     }
 
@@ -49,7 +49,7 @@
     inline typename result_of::as_deque<Sequence const>::type
     as_deque(Sequence const& seq)
     {
- typedef typename result_of::as_deque<Sequence const>::gen gen;
+ typedef result_of::as_deque<Sequence const> gen;
         return gen::call(fusion::begin(seq), fusion::end(seq));
     }
 }}

Modified: trunk/boost/fusion/container/map/convert.hpp
==============================================================================
--- trunk/boost/fusion/container/map/convert.hpp (original)
+++ trunk/boost/fusion/container/map/convert.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -7,6 +7,51 @@
 #if !defined(FUSION_CONVERT_MAIN_09232005_1340)
 #define FUSION_CONVERT_MAIN_09232005_1340
 
-#include <boost/fusion/container/map/detail/cpp03/convert.hpp>
+#include <boost/fusion/container/map/map.hpp>
 
+///////////////////////////////////////////////////////////////////////////////
+// Without variadics, we will use the PP version
+///////////////////////////////////////////////////////////////////////////////
+#if !defined(BOOST_FUSION_HAS_VARIADIC_MAP)
+# include <boost/fusion/container/map/detail/cpp03/convert.hpp>
+
+#else
+///////////////////////////////////////////////////////////////////////////////
+// C++11 variadic implementation
+///////////////////////////////////////////////////////////////////////////////
+#include <boost/fusion/container/map/detail/build_map.hpp>
+
+namespace boost { namespace fusion
+{
+ namespace result_of
+ {
+ template <typename Sequence>
+ struct as_map :
+ detail::build_map<
+ typename result_of::begin<Sequence>::type
+ , typename result_of::end<Sequence>::type
+ >
+ {
+ };
+ }
+
+ template <typename Sequence>
+ inline typename result_of::as_map<Sequence>::type
+ as_map(Sequence& seq)
+ {
+ typedef result_of::as_map<Sequence> gen;
+ return gen::call(fusion::begin(seq), fusion::end(seq));
+ }
+
+ template <typename Sequence>
+ inline typename result_of::as_map<Sequence const>::type
+ as_map(Sequence const& seq)
+ {
+ typedef result_of::as_map<Sequence const> gen;
+ return gen::call(fusion::begin(seq), fusion::end(seq));
+ }
+}}
+
+#endif
 #endif
+

Modified: trunk/boost/fusion/container/map/detail/at_impl.hpp
==============================================================================
--- trunk/boost/fusion/container/map/detail/at_impl.hpp (original)
+++ trunk/boost/fusion/container/map/detail/at_impl.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -24,28 +24,30 @@
             template <typename Sequence, typename N>
             struct apply
             {
+ typedef mpl::int_<N::value> index;
                 typedef
- decltype(std::declval<Sequence>().get(N()))
+ decltype(std::declval<Sequence>().get(index()))
                 type;
 
                 static type
                 call(Sequence& m)
                 {
- return m.get(N());
+ return m.get(index());
                 }
             };
 
             template <typename Sequence, typename N>
             struct apply<Sequence const, N>
             {
+ typedef mpl::int_<N::value> index;
                 typedef
- decltype(std::declval<Sequence const>().get(N()))
+ decltype(std::declval<Sequence const>().get(index()))
                 type;
 
                 static type
                 call(Sequence const& m)
                 {
- return m.get(N());
+ return m.get(index());
                 }
             };
         };

Added: trunk/boost/fusion/container/map/detail/build_map.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/container/map/detail/build_map.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -0,0 +1,75 @@
+/*=============================================================================
+ Copyright (c) 2005-2013 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_BUILD_MAP_02042013_1448)
+#define BOOST_FUSION_BUILD_MAP_02042013_1448
+
+#include <boost/fusion/iterator/equal_to.hpp>
+#include <boost/fusion/iterator/next.hpp>
+#include <boost/fusion/iterator/value_of.hpp>
+#include <boost/fusion/iterator/deref.hpp>
+#include <boost/fusion/sequence/intrinsic/begin.hpp>
+#include <boost/fusion/sequence/intrinsic/end.hpp>
+#include <boost/fusion/container/map/map.hpp>
+#include <boost/fusion/algorithm/transformation/push_front.hpp>
+
+namespace boost { namespace fusion { namespace detail
+{
+ template <typename First, typename Last
+ , bool is_empty = result_of::equal_to<First, Last>::value>
+ struct build_map;
+
+ template <typename First, typename Last>
+ struct build_map<First, Last, true>
+ {
+ typedef map<> type;
+ static type
+ call(First const&, Last const&)
+ {
+ return type();
+ }
+ };
+
+ template <typename T, typename Rest>
+ struct push_front_map;
+
+ template <typename T, typename ...Rest>
+ struct push_front_map<T, map<Rest...>>
+ {
+ typedef map<T, Rest...> type;
+
+ static type
+ call(T const& first, map<Rest...> const& rest)
+ {
+ return type(push_front(rest, first));
+ }
+ };
+
+ template <typename First, typename Last>
+ struct build_map<First, Last, false>
+ {
+ typedef
+ build_map<typename result_of::next<First>::type, Last>
+ next_build_map;
+
+ typedef push_front_map<
+ typename result_of::value_of<First>::type
+ , typename next_build_map::type>
+ push_front;
+
+ typedef typename push_front::type type;
+
+ static type
+ call(First const& f, Last const& l)
+ {
+ typename result_of::value_of<First>::type v = *f;
+ return push_front::call(
+ v, next_build_map::call(fusion::next(f), l));
+ }
+ };
+}}}
+
+#endif

Added: trunk/boost/fusion/container/map/detail/map_index.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/container/map/detail/map_index.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -0,0 +1,19 @@
+/*=============================================================================
+ Copyright (c) 2005-2013 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_MAP_INDEX_02032013_2233)
+#define BOOST_FUSION_MAP_INDEX_02032013_2233
+
+namespace boost { namespace fusion { namespace detail
+{
+ template <int N>
+ struct map_index
+ {
+ static int const value = N;
+ };
+}}}
+
+#endif

Modified: trunk/boost/fusion/container/map/map.hpp
==============================================================================
--- trunk/boost/fusion/container/map/map.hpp (original)
+++ trunk/boost/fusion/container/map/map.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -58,6 +58,12 @@
           : base_type(begin(seq), detail::map_impl_from_iterator())
         {}
 
+ template <typename Sequence>
+ map(Sequence& seq
+ , typename enable_if<traits::is_sequence<Sequence>>::type* /*dummy*/ = 0)
+ : base_type(begin(seq), detail::map_impl_from_iterator())
+ {}
+
         template <typename First, typename ...T_>
         map(First const& first, T_ const&... rest)
           : base_type(first, rest...)

Modified: trunk/boost/fusion/container/map/map_iterator.hpp
==============================================================================
--- trunk/boost/fusion/container/map/map_iterator.hpp (original)
+++ trunk/boost/fusion/container/map/map_iterator.hpp 2013-02-04 04:52:52 EST (Mon, 04 Feb 2013)
@@ -20,7 +20,7 @@
     struct map_iterator
         : iterator_facade<
             map_iterator<Seq, Pos>
- , random_access_traversal_tag>
+ , typename Seq::category>
     {
         typedef Seq sequence;
         typedef mpl::int_<Pos> index;
@@ -91,22 +91,6 @@
             }
         };
 
- //~ template<typename Iterator>
- //~ struct deref_data
- //~ {
- //~ typedef typename Iterator::sequence sequence;
- //~ typedef typename Iterator::index index;
- //~ typedef
- //~ decltype(std::declval<sequence>().get(index()))
- //~ type;
-
- //~ static type
- //~ call(Iterator const& it)
- //~ {
- //~ return it.seq_.get(typename Iterator::index());
- //~ }
- //~ };
-
         template <typename Iterator, typename N>
         struct advance
         {
@@ -132,7 +116,7 @@
         {};
 
         template <typename I1, typename I2>
- struct distance : mpl::minus<typename I2::index, typename I1::index>
+ struct distance
         {
             typedef typename
                 mpl::minus<


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