From b6df98e86c08c30342afc3d59bd963bbfd686d49 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Mon, 10 Oct 2011 09:55:41 +0000 Subject: [PATCH] Made map random access. Thanks to Brandon Kohn! [SVN r74881] --- .../fusion/container/map/detail/at_impl.hpp | 57 +++++++++++++++++++ .../map/detail/preprocessed/map10.hpp | 2 +- .../map/detail/preprocessed/map20.hpp | 2 +- .../map/detail/preprocessed/map30.hpp | 2 +- .../map/detail/preprocessed/map40.hpp | 2 +- .../map/detail/preprocessed/map50.hpp | 2 +- .../container/map/detail/value_at_impl.hpp | 34 +++++++++++ include/boost/fusion/container/map/map.hpp | 4 +- 8 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 include/boost/fusion/container/map/detail/at_impl.hpp create mode 100644 include/boost/fusion/container/map/detail/value_at_impl.hpp diff --git a/include/boost/fusion/container/map/detail/at_impl.hpp b/include/boost/fusion/container/map/detail/at_impl.hpp new file mode 100644 index 00000000..f871bee0 --- /dev/null +++ b/include/boost/fusion/container/map/detail/at_impl.hpp @@ -0,0 +1,57 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 Brandon Kohn + + 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_DETAIL_AT_IMPL_HPP) +#define BOOST_FUSION_MAP_DETAIL_AT_IMPL_HPP + +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct map_tag; + + namespace extension + { + template + struct at_impl; + + template <> + struct at_impl + { + template + struct apply + { + typedef mpl::at element; + typedef typename detail::ref_result::type type; + + static type + call(Sequence& m) + { + return m.get_data().at_impl(N()); + } + }; + + template + struct apply + { + typedef mpl::at element; + typedef typename detail::cref_result::type type; + + static type + call(Sequence const& m) + { + return m.get_data().at_impl(N()); + } + }; + }; + } +}} + +#endif //BOOST_FUSION_MAP_DETAIL_AT_IMPL_HPP diff --git a/include/boost/fusion/container/map/detail/preprocessed/map10.hpp b/include/boost/fusion/container/map/detail/preprocessed/map10.hpp index cae643d8..fdf28eb2 100644 --- a/include/boost/fusion/container/map/detail/preprocessed/map10.hpp +++ b/include/boost/fusion/container/map/detail/preprocessed/map10.hpp @@ -13,7 +13,7 @@ namespace boost { namespace fusion template struct map : sequence_base > { - struct category : forward_traversal_tag, associative_tag {}; + struct category : random_access_traversal_tag, associative_tag {}; typedef map_tag fusion_tag; typedef fusion_sequence_tag tag; typedef mpl::false_ is_view; diff --git a/include/boost/fusion/container/map/detail/preprocessed/map20.hpp b/include/boost/fusion/container/map/detail/preprocessed/map20.hpp index 01105265..33cd2e59 100644 --- a/include/boost/fusion/container/map/detail/preprocessed/map20.hpp +++ b/include/boost/fusion/container/map/detail/preprocessed/map20.hpp @@ -13,7 +13,7 @@ namespace boost { namespace fusion template struct map : sequence_base > { - struct category : forward_traversal_tag, associative_tag {}; + struct category : random_access_traversal_tag, associative_tag {}; typedef map_tag fusion_tag; typedef fusion_sequence_tag tag; typedef mpl::false_ is_view; diff --git a/include/boost/fusion/container/map/detail/preprocessed/map30.hpp b/include/boost/fusion/container/map/detail/preprocessed/map30.hpp index ede29720..54f492d0 100644 --- a/include/boost/fusion/container/map/detail/preprocessed/map30.hpp +++ b/include/boost/fusion/container/map/detail/preprocessed/map30.hpp @@ -13,7 +13,7 @@ namespace boost { namespace fusion template struct map : sequence_base > { - struct category : forward_traversal_tag, associative_tag {}; + struct category : random_access_traversal_tag, associative_tag {}; typedef map_tag fusion_tag; typedef fusion_sequence_tag tag; typedef mpl::false_ is_view; diff --git a/include/boost/fusion/container/map/detail/preprocessed/map40.hpp b/include/boost/fusion/container/map/detail/preprocessed/map40.hpp index 6a75d2c6..7060a670 100644 --- a/include/boost/fusion/container/map/detail/preprocessed/map40.hpp +++ b/include/boost/fusion/container/map/detail/preprocessed/map40.hpp @@ -13,7 +13,7 @@ namespace boost { namespace fusion template struct map : sequence_base > { - struct category : forward_traversal_tag, associative_tag {}; + struct category : random_access_traversal_tag, associative_tag {}; typedef map_tag fusion_tag; typedef fusion_sequence_tag tag; typedef mpl::false_ is_view; diff --git a/include/boost/fusion/container/map/detail/preprocessed/map50.hpp b/include/boost/fusion/container/map/detail/preprocessed/map50.hpp index f9c36302..1da73641 100644 --- a/include/boost/fusion/container/map/detail/preprocessed/map50.hpp +++ b/include/boost/fusion/container/map/detail/preprocessed/map50.hpp @@ -13,7 +13,7 @@ namespace boost { namespace fusion template struct map : sequence_base > { - struct category : forward_traversal_tag, associative_tag {}; + struct category : random_access_traversal_tag, associative_tag {}; typedef map_tag fusion_tag; typedef fusion_sequence_tag tag; typedef mpl::false_ is_view; diff --git a/include/boost/fusion/container/map/detail/value_at_impl.hpp b/include/boost/fusion/container/map/detail/value_at_impl.hpp new file mode 100644 index 00000000..31d9b383 --- /dev/null +++ b/include/boost/fusion/container/map/detail/value_at_impl.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 Brandon Kohn + + 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_DETAIL_VALUE_AT_IMPL_HPP) +#define BOOST_FUSION_MAP_DETAIL_VALUE_AT_IMPL_HPP + +#include + +namespace boost { namespace fusion +{ + struct map_tag; + + namespace extension + { + template + struct value_at_impl; + + template <> + struct value_at_impl + { + template + struct apply + { + typedef typename mpl::at::type type; + }; + }; + } +}} + +#endif //BOOST_FUSION_MAP_DETAIL_VALUE_AT_IMPL_HPP diff --git a/include/boost/fusion/container/map/map.hpp b/include/boost/fusion/container/map/map.hpp index d61df914..5152e6e1 100644 --- a/include/boost/fusion/container/map/map.hpp +++ b/include/boost/fusion/container/map/map.hpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -50,7 +52,7 @@ namespace boost { namespace fusion template struct map : sequence_base > { - struct category : forward_traversal_tag, associative_tag {}; + struct category : random_access_traversal_tag, associative_tag {}; typedef map_tag fusion_tag; typedef fusion_sequence_tag tag; // this gets picked up by MPL