From 6002bc9bb4d1c219994d3dc459bf201352567e89 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Mon, 2 Apr 2007 03:31:13 +0000 Subject: [PATCH] added struct wrapping facilities to make it very easy to make any struct a conforming fusion sequence [SVN r37328] --- include/boost/fusion/sequence/adapted/mpl.hpp | 3 +- .../fusion/sequence/adapted/std_pair.hpp | 65 ++++++++-- .../adapted/std_pair/Attic/tag_of.hpp | 29 ----- .../boost/fusion/sequence/adapted/struct.hpp | 20 ++++ .../Attic => struct/detail}/at_impl.hpp | 50 ++++---- .../Attic => struct/detail}/begin_impl.hpp | 18 +-- .../detail}/category_of_impl.hpp | 10 +- .../Attic => struct/detail}/end_impl.hpp | 18 +-- .../detail}/is_sequence_impl.hpp | 10 +- .../Attic => struct/detail}/is_view_impl.hpp | 8 +- .../Attic => struct/detail}/size_impl.hpp | 16 ++- .../Attic => struct/detail}/value_at_impl.hpp | 28 +++-- .../struct_iterator.hpp} | 111 +++++++++--------- 13 files changed, 214 insertions(+), 172 deletions(-) delete mode 100644 include/boost/fusion/sequence/adapted/std_pair/Attic/tag_of.hpp create mode 100644 include/boost/fusion/sequence/adapted/struct.hpp rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/at_impl.hpp (57%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/begin_impl.hpp (74%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/category_of_impl.hpp (86%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/end_impl.hpp (74%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/is_sequence_impl.hpp (85%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/is_view_impl.hpp (86%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/size_impl.hpp (71%) rename include/boost/fusion/sequence/adapted/{std_pair/detail/Attic => struct/detail}/value_at_impl.hpp (65%) rename include/boost/fusion/sequence/adapted/{std_pair/Attic/std_pair_iterator.hpp => struct/struct_iterator.hpp} (51%) diff --git a/include/boost/fusion/sequence/adapted/mpl.hpp b/include/boost/fusion/sequence/adapted/mpl.hpp index 643a587c..94f4967a 100644 --- a/include/boost/fusion/sequence/adapted/mpl.hpp +++ b/include/boost/fusion/sequence/adapted/mpl.hpp @@ -2,13 +2,12 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_MPL_31122005_1152) #define BOOST_FUSION_MPL_31122005_1152 -#include #include #include #include diff --git a/include/boost/fusion/sequence/adapted/std_pair.hpp b/include/boost/fusion/sequence/adapted/std_pair.hpp index d4ba0b68..0b755a0b 100644 --- a/include/boost/fusion/sequence/adapted/std_pair.hpp +++ b/include/boost/fusion/sequence/adapted/std_pair.hpp @@ -2,20 +2,65 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_STD_PAIR_24122005_1744) #define BOOST_FUSION_STD_PAIR_24122005_1744 -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct struct_tag; + + namespace traits + { + template + struct tag_of > + { + typedef struct_tag type; + }; + } + + namespace extension + { + template + struct struct_member; + + template + struct struct_size; + + template + struct struct_member, 0> + { + typedef T1 type; + + static type& call(std::pair& pair) + { + return pair.first; + } + }; + + template + struct struct_member, 1> + { + typedef T2 type; + + static type& call(std::pair& pair) + { + return pair.second; + } + }; + + template + struct struct_size > : mpl::int_<2> + { + }; + } +}} #endif diff --git a/include/boost/fusion/sequence/adapted/std_pair/Attic/tag_of.hpp b/include/boost/fusion/sequence/adapted/std_pair/Attic/tag_of.hpp deleted file mode 100644 index 3211efad..00000000 --- a/include/boost/fusion/sequence/adapted/std_pair/Attic/tag_of.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/*============================================================================= - Copyright (c) 2001-2006 Joel de Guzman - Copyright (c) 2005-2006 Dan Marsden - - 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_24122005_1722) -#define BOOST_FUSION_TAG_OF_24122005_1722 - -#include - -#include - -namespace boost { namespace fusion { - - struct std_pair_tag; - - namespace traits - { - template - struct tag_of > - { - typedef std_pair_tag type; - }; - } -}} - -#endif diff --git a/include/boost/fusion/sequence/adapted/struct.hpp b/include/boost/fusion/sequence/adapted/struct.hpp new file mode 100644 index 00000000..1b52fd7c --- /dev/null +++ b/include/boost/fusion/sequence/adapted/struct.hpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 2001-2006 Joel de Guzman + Copyright (c) 2005-2006 Dan Marsden + + 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_STRUCT_24122005_1744) +#define BOOST_FUSION_STD_STRUCT_24122005_1744 + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/at_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/at_impl.hpp similarity index 57% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/at_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/at_impl.hpp index 2f26fa68..809902ae 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/at_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/at_impl.hpp @@ -2,40 +2,43 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_AT_IMPL_24122005_1807) #define BOOST_FUSION_AT_IMPL_24122005_1807 -#include -#include -#include #include +#include +#include -namespace boost { namespace fusion { - - struct std_pair_tag; +namespace boost { namespace fusion +{ + struct struct_tag; namespace extension { template struct at_impl; + template + struct struct_member; + + template + struct struct_size; + template <> - struct at_impl + struct at_impl { template - struct apply + struct apply { static int const n_value = N::value; - BOOST_STATIC_ASSERT((n_value >= 0 && n_value < 2)); + BOOST_MPL_ASSERT_RELATION( + n_value, <=, extension::struct_size::value); + typedef typename - mpl::if_c< - (n_value == 0) - , typename Sequence::first_type - , typename Sequence::second_type - > + extension::struct_member element; typedef typename @@ -46,22 +49,11 @@ namespace boost { namespace fusion { >::type type; - template - static RT get(Sequence& p, mpl::int_<0>) - { - return p.first; - } - - template - static RT get(Sequence& p, mpl::int_<1>) - { - return p.second; - } - static type - call(Sequence& p) + call(Sequence& seq) { - return get(p, N()); + return extension:: + struct_member::call(seq); } }; }; diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/begin_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/begin_impl.hpp similarity index 74% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/begin_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/begin_impl.hpp index 1b77b7a7..14817726 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/begin_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/begin_impl.hpp @@ -2,17 +2,17 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_BEGIN_IMPL_24122005_1752) #define BOOST_FUSION_BEGIN_IMPL_24122005_1752 -#include +#include -namespace boost { namespace fusion { - - struct std_pair_tag; +namespace boost { namespace fusion +{ + struct struct_tag; namespace extension { @@ -20,13 +20,13 @@ namespace boost { namespace fusion { struct begin_impl; template <> - struct begin_impl + struct begin_impl { template - struct apply + struct apply { - typedef std_pair_iterator type; - + typedef struct_iterator type; + static type call(Sequence& v) { diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/category_of_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/category_of_impl.hpp similarity index 86% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/category_of_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/category_of_impl.hpp index f207c1c7..9e7f9df4 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/category_of_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/category_of_impl.hpp @@ -2,7 +2,7 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_CATEGORY_OF_IMPL_24122005_1731) @@ -10,9 +10,9 @@ #include -namespace boost { namespace fusion { - - struct std_pair_tag; +namespace boost { namespace fusion +{ + struct struct_tag; struct random_access_traversal_tag; namespace extension @@ -21,7 +21,7 @@ namespace boost { namespace fusion { struct category_of_impl; template<> - struct category_of_impl + struct category_of_impl { template struct apply diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/end_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/end_impl.hpp similarity index 74% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/end_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/end_impl.hpp index 9aab76c5..91830cea 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/end_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/end_impl.hpp @@ -2,17 +2,17 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_END_IMPL_24122005_1755) #define BOOST_FUSION_END_IMPL_24122005_1755 -#include +#include -namespace boost { namespace fusion { - - struct std_pair_tag; +namespace boost { namespace fusion +{ + struct struct_tag; namespace extension { @@ -20,13 +20,13 @@ namespace boost { namespace fusion { struct end_impl; template <> - struct end_impl + struct end_impl { template - struct apply + struct apply { - typedef std_pair_iterator type; - + typedef struct_iterator type; + static type call(Sequence& v) { diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/is_sequence_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/is_sequence_impl.hpp similarity index 85% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/is_sequence_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/is_sequence_impl.hpp index 1c669a68..f81e9fb6 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/is_sequence_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/is_sequence_impl.hpp @@ -2,7 +2,7 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_IS_SEQUENCE_IMPL_27122005_1651) @@ -10,9 +10,9 @@ #include -namespace boost { namespace fusion { - - struct std_pair_tag; +namespace boost { namespace fusion +{ + struct struct_tag; namespace extension { @@ -20,7 +20,7 @@ namespace boost { namespace fusion { struct is_sequence_impl; template<> - struct is_sequence_impl + struct is_sequence_impl { template struct apply : mpl::true_ {}; diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/is_view_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/is_view_impl.hpp similarity index 86% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/is_view_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/is_view_impl.hpp index 94842bc0..da6f380b 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/is_view_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/is_view_impl.hpp @@ -2,7 +2,7 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_IS_VIEW_IMPL_27042006_2219) @@ -10,9 +10,9 @@ #include -namespace boost { namespace fusion +namespace boost { namespace fusion { - struct std_pair_tag; + struct struct_tag; namespace extension { @@ -20,7 +20,7 @@ namespace boost { namespace fusion struct is_view_impl; template<> - struct is_view_impl + struct is_view_impl { template struct apply : mpl::false_ diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/size_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/size_impl.hpp similarity index 71% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/size_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/size_impl.hpp index 5f35bffd..12ec14ba 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/size_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/size_impl.hpp @@ -2,7 +2,7 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_SIZE_IMPL_24122005_1759) @@ -10,9 +10,15 @@ #include -namespace boost { namespace fusion { +namespace boost { namespace fusion +{ + namespace extension + { + template + struct struct_size; + } - struct std_pair_tag; + struct struct_tag; namespace extension { @@ -20,10 +26,10 @@ namespace boost { namespace fusion { struct size_impl; template <> - struct size_impl + struct size_impl { template - struct apply : mpl::int_<2> {}; + struct apply : extension::struct_size {}; }; } }} diff --git a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/value_at_impl.hpp b/include/boost/fusion/sequence/adapted/struct/detail/value_at_impl.hpp similarity index 65% rename from include/boost/fusion/sequence/adapted/std_pair/detail/Attic/value_at_impl.hpp rename to include/boost/fusion/sequence/adapted/struct/detail/value_at_impl.hpp index 16047ec9..8f5d97a0 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/detail/Attic/value_at_impl.hpp +++ b/include/boost/fusion/sequence/adapted/struct/detail/value_at_impl.hpp @@ -2,7 +2,7 @@ Copyright (c) 2001-2006 Joel de Guzman Copyright (c) 2005-2006 Dan Marsden - 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(BOOST_FUSION_VALUE_AT_IMPL_24122005_1917) @@ -11,29 +11,33 @@ #include #include -namespace boost { namespace fusion { - - struct std_pair_tag; +namespace boost { namespace fusion +{ + struct struct_tag; namespace extension { template struct value_at_impl; + template + struct struct_member; + + template + struct struct_size; + template <> - struct value_at_impl + struct value_at_impl { template - struct apply + struct apply { static int const n_value = N::value; - BOOST_STATIC_ASSERT((n_value >= 0 && n_value < 2)); + BOOST_MPL_ASSERT_RELATION( + n_value, <=, extension::struct_size::value); + typedef typename - mpl::if_c< - (n_value == 0) - , typename Sequence::first_type - , typename Sequence::second_type - >::type + extension::struct_member::type type; }; }; diff --git a/include/boost/fusion/sequence/adapted/std_pair/Attic/std_pair_iterator.hpp b/include/boost/fusion/sequence/adapted/struct/struct_iterator.hpp similarity index 51% rename from include/boost/fusion/sequence/adapted/std_pair/Attic/std_pair_iterator.hpp rename to include/boost/fusion/sequence/adapted/struct/struct_iterator.hpp index 4aa2daa2..0684deaf 100644 --- a/include/boost/fusion/sequence/adapted/std_pair/Attic/std_pair_iterator.hpp +++ b/include/boost/fusion/sequence/adapted/struct/struct_iterator.hpp @@ -1,14 +1,17 @@ /*============================================================================= - Copyright (c) 2001-2006 Joel de Guzman + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2005-2006 Dan Marsden - 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_STD_PAIR_ITERATOR_09262005_0934) -#define FUSION_STD_PAIR_ITERATOR_09262005_0934 +#if !defined(FUSION_STRUCT_ITERATOR_APRIL_2_2007_1008AM) +#define FUSION_STRUCT_ITERATOR_APRIL_2_2007_1008AM #include #include +#include +#include #include #include #include @@ -18,69 +21,71 @@ namespace boost { namespace fusion { - struct random_access_traversal_tag; - - template - struct std_pair_iterator - : iterator_facade, random_access_traversal_tag> + namespace extension { - BOOST_MPL_ASSERT_RELATION(N_, >=, 0); - BOOST_MPL_ASSERT_RELATION(N_, <=, 2); + template + struct struct_member; - typedef mpl::int_ index; - typedef Pair_ pair_type; + template + struct struct_size; - std_pair_iterator(Pair_& pair) - : pair(pair) {} - Pair_& pair; - - template - struct value_of; - - template - struct value_of > - : mpl::identity {}; - - template - struct value_of > - : mpl::identity {}; - - template - struct deref; - - template - struct deref > + template + struct struct_member { typedef typename - mpl::if_< - is_const - , typename Pair::first_type const& - , typename Pair::first_type& - >::type + add_const::type>::type type; - static type - call(std_pair_iterator const& iter) + static type& + call(Struct const& struct_) { - return iter.pair.first; + return struct_member::call( + const_cast(struct_)); } }; - template - struct deref > + template + struct struct_size + : struct_size + {}; + } + + struct random_access_traversal_tag; + + template + struct struct_iterator + : iterator_facade, random_access_traversal_tag> + { + BOOST_MPL_ASSERT_RELATION(N_, >=, 0); + BOOST_MPL_ASSERT_RELATION(N_, <=, extension::struct_size::value); + + typedef mpl::int_ index; + typedef Struct struct_type; + + struct_iterator(Struct& struct_) + : struct_(struct_) {} + Struct& struct_; + + template + struct value_of + : extension::struct_member + { + }; + + template + struct deref { typedef typename - mpl::if_< - is_const - , typename Pair::second_type const& - , typename Pair::second_type& + add_reference< + typename extension::struct_member::type >::type type; static type - call(std_pair_iterator const& iter) + call(Iterator const& iter) { - return iter.pair.second; + return extension::struct_member:: + call(iter.struct_); } }; @@ -88,13 +93,13 @@ namespace boost { namespace fusion struct advance { typedef typename Iterator::index index; - typedef typename Iterator::pair_type pair_type; - typedef std_pair_iterator type; + typedef typename Iterator::struct_type struct_type; + typedef struct_iterator type; static type call(Iterator const& iter) { - return type(iter.pair); + return type(iter.struct_); } }; @@ -110,7 +115,7 @@ namespace boost { namespace fusion typedef typename mpl::minus< typename I2::index, typename I1::index - >::type + >::type type; static type