diff options
Diffstat (limited to 'src/boost/libs/fusion/example/extension')
28 files changed, 1553 insertions, 0 deletions
diff --git a/src/boost/libs/fusion/example/extension/Jamfile b/src/boost/libs/fusion/example/extension/Jamfile new file mode 100644 index 00000000..aabe8302 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/Jamfile @@ -0,0 +1,20 @@ +#============================================================================== +# Copyright (c) 2003-2006 Joel de Guzman +# Copyright (c) 2006 Dan Marsden +# +# Use, modification and distribution is subject to 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) +#============================================================================== + +# bring in rules for testing +import testing ; + +{ + test-suite example : + + [ run test_example.cpp : : : : ] + [ run triple.cpp : : : : ] + ; +} + diff --git a/src/boost/libs/fusion/example/extension/detail/advance_impl.hpp b/src/boost/libs/fusion/example/extension/detail/advance_impl.hpp new file mode 100644 index 00000000..0d778123 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/advance_impl.hpp @@ -0,0 +1,47 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_ADVANCE_IMPL_20060222_2150) +#define BOOST_FUSION_ADVANCE_IMPL_20060222_2150 + +namespace example +{ + struct example_struct_iterator_tag; + + template<typename Struct, int Pos> + struct example_struct_iterator; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct advance_impl; + + template<> + struct advance_impl<example::example_struct_iterator_tag> + { + template<typename Iterator, typename N> + struct apply + { + typedef typename Iterator::struct_type struct_type; + typedef typename Iterator::index index; + typedef example::example_struct_iterator< + struct_type, index::value + N::value> type; + + static type + call(Iterator const& it) + { + return type(it.struct_); + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/at_impl.hpp b/src/boost/libs/fusion/example/extension/detail/at_impl.hpp new file mode 100644 index 00000000..60558930 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/at_impl.hpp @@ -0,0 +1,67 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_AT_IMPL_20060223_2017) +#define BOOST_FUSION_AT_IMPL_20060223_2017 + +#include <string> +#include <boost/mpl/if.hpp> +#include <boost/mpl/int.hpp> +#include <boost/type_traits/is_const.hpp> + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct at_impl; + + template<> + struct at_impl<example::example_sequence_tag> + { + template<typename Sequence, typename Key> + struct apply; + + template<typename Sequence> + struct apply<Sequence, mpl::int_<0> > + { + typedef typename mpl::if_< + is_const<Sequence>, + std::string const&, + std::string&>::type type; + + static type + call(Sequence& seq) + { + return seq.name; + }; + }; + + template<typename Sequence> + struct apply<Sequence, mpl::int_<1> > + { + typedef typename mpl::if_< + is_const<Sequence>, + int const&, + int&>::type type; + + static type + call(Sequence& seq) + { + return seq.age; + }; + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/at_key_impl.hpp b/src/boost/libs/fusion/example/extension/detail/at_key_impl.hpp new file mode 100644 index 00000000..e925c62a --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/at_key_impl.hpp @@ -0,0 +1,72 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_AT_KEY_IMPL_20060223_2017) +#define BOOST_FUSION_AT_KEY_IMPL_20060223_2017 + +#include <string> +#include <boost/mpl/if.hpp> +#include <boost/type_traits/is_const.hpp> + +namespace fields +{ + struct name; + struct age; +} + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct at_key_impl; + + template<> + struct at_key_impl<example::example_sequence_tag> + { + template<typename Sequence, typename Key> + struct apply; + + template<typename Sequence> + struct apply<Sequence, fields::name> + { + typedef typename mpl::if_< + is_const<Sequence>, + std::string const&, + std::string&>::type type; + + static type + call(Sequence& seq) + { + return seq.name; + }; + }; + + template<typename Sequence> + struct apply<Sequence, fields::age> + { + typedef typename mpl::if_< + is_const<Sequence>, + int const&, + int&>::type type; + + static type + call(Sequence& seq) + { + return seq.age; + }; + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/begin_impl.hpp b/src/boost/libs/fusion/example/extension/detail/begin_impl.hpp new file mode 100644 index 00000000..a4296c59 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/begin_impl.hpp @@ -0,0 +1,43 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_BEGIN_IMPL_20060222_2042) +#define BOOST_FUSION_BEGIN_IMPL_20060222_2042 + +#include "../example_struct_iterator.hpp" + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct begin_impl; + + template<> + struct begin_impl<example::example_sequence_tag> + { + template<typename Sequence> + struct apply + { + typedef example::example_struct_iterator<Sequence, 0> type; + + static type + call(Sequence& seq) + { + return type(seq); + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/category_of_impl.hpp b/src/boost/libs/fusion/example/extension/detail/category_of_impl.hpp new file mode 100644 index 00000000..b0bc7d90 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/category_of_impl.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_CATEGORY_OF_IMPL_20060223_2037) +#define BOOST_FUSION_CATEGORY_OF_IMPL_20060223_2037 + +#include <boost/fusion/support/category_of.hpp> + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<> + struct category_of_impl<example::example_sequence_tag> + { + template<typename Sequence> + struct apply + { + struct type : random_access_traversal_tag, associative_tag {}; + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/deref_data_impl.hpp b/src/boost/libs/fusion/example/extension/detail/deref_data_impl.hpp new file mode 100644 index 00000000..c9907d5c --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/deref_data_impl.hpp @@ -0,0 +1,30 @@ +/*============================================================================= + Copyright (c) 2009 Christopher Schmidt + + 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) +==============================================================================*/ + +#ifndef BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_DEREF_DATA_IMPL_HPP +#define BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_DEREF_DATA_IMPL_HPP + +namespace example +{ + struct example_struct_iterator_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct deref_data_impl; + + template<> + struct deref_data_impl<example::example_struct_iterator_tag> + : deref_impl<example::example_struct_iterator_tag> + {}; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/deref_impl.hpp b/src/boost/libs/fusion/example/extension/detail/deref_impl.hpp new file mode 100644 index 00000000..7e515e9d --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/deref_impl.hpp @@ -0,0 +1,67 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_DEREF_IMPL_20060222_1952) +#define BOOST_FUSION_DEREF_IMPL_20060222_1952 + +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_const.hpp> +#include <boost/mpl/if.hpp> + +#include <string> + +namespace example +{ + struct example_struct_iterator_tag; + + template<typename Struct, int Pos> + struct example_struct_iterator; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct deref_impl; + + template<> + struct deref_impl<example::example_struct_iterator_tag> + { + template<typename Iterator> + struct apply; + + template<typename Struct> + struct apply<example::example_struct_iterator<Struct, 0> > + { + typedef typename mpl::if_< + is_const<Struct>, std::string const&, std::string&>::type type; + + static type + call(example::example_struct_iterator<Struct, 0> const& it) + { + return it.struct_.name; + } + }; + + template<typename Struct> + struct apply<example::example_struct_iterator<Struct, 1> > + { + typedef typename mpl::if_< + is_const<Struct>, int const&, int&>::type type; + + static type + call(example::example_struct_iterator<Struct, 1> const& it) + { + return it.struct_.age; + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/distance_impl.hpp b/src/boost/libs/fusion/example/extension/detail/distance_impl.hpp new file mode 100644 index 00000000..b138cc4a --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/distance_impl.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_DISTANCE_IMPL_20060223_0814) +#define BOOST_FUSION_DISTANCE_IMPL_20060223_0814 + +#include <boost/mpl/minus.hpp> + +namespace example +{ + struct example_struct_iterator_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct distance_impl; + + template<> + struct distance_impl<example::example_struct_iterator_tag> + { + template<typename First, typename Last> + struct apply + : mpl::minus<typename Last::index, typename First::index> + { + typedef apply<First, Last> self; + + static typename self::type + call(First const& first, Last const& last) + { + return typename self::type(); + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/end_impl.hpp b/src/boost/libs/fusion/example/extension/detail/end_impl.hpp new file mode 100644 index 00000000..749bb33a --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/end_impl.hpp @@ -0,0 +1,43 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_END_IMPL_20060222_2042) +#define BOOST_FUSION_END_IMPL_20060222_2042 + +#include "../example_struct_iterator.hpp" + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct end_impl; + + template<> + struct end_impl<example::example_sequence_tag> + { + template<typename Sequence> + struct apply + { + typedef example::example_struct_iterator<Sequence, 2> type; + + static type + call(Sequence& seq) + { + return type(seq); + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/equal_to_impl.hpp b/src/boost/libs/fusion/example/extension/detail/equal_to_impl.hpp new file mode 100644 index 00000000..8ab27649 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/equal_to_impl.hpp @@ -0,0 +1,38 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_EQUAL_TO_IMPL_20060223_1941) +#define BOOST_FUSION_EQUAL_TO_IMPL_20060223_1941 + +#include <boost/mpl/equal_to.hpp> + +namespace example +{ + struct example_struct_iterator_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct equal_to_impl; + + template<> + struct equal_to_impl<example::example_struct_iterator_tag> + { + template<typename It1, typename It2> + struct apply + : mpl::equal_to< + typename It1::index, + typename It2::index> + {}; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/has_key_impl.hpp b/src/boost/libs/fusion/example/extension/detail/has_key_impl.hpp new file mode 100644 index 00000000..596827ce --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/has_key_impl.hpp @@ -0,0 +1,45 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_HAS_KEY_IMPL_20060223_2156) +#define BOOST_FUSION_HAS_KEY_IMPL_20060223_2156 + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/or.hpp> + +namespace fields +{ + struct name; + struct age; +} + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct has_key_impl; + + template<> + struct has_key_impl<example::example_sequence_tag> + { + template<typename Sequence, typename Key> + struct apply + : mpl::or_< + is_same<Key, fields::name>, + is_same<Key, fields::age> > + {}; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/is_sequence_impl.hpp b/src/boost/libs/fusion/example/extension/detail/is_sequence_impl.hpp new file mode 100644 index 00000000..e373342a --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/is_sequence_impl.hpp @@ -0,0 +1,34 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_IS_SEQUENCE_IMPL_20060228_1946) +#define BOOST_FUSION_IS_SEQUENCE_IMPL_20060228_1946 + +#include <boost/mpl/bool.hpp> + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion +{ + namespace extension + { + template<typename Tag> + struct is_sequence_impl; + + template<> + struct is_sequence_impl<example::example_sequence_tag> + { + template<typename T> + struct apply : mpl::true_ {}; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/is_view_impl.hpp b/src/boost/libs/fusion/example/extension/detail/is_view_impl.hpp new file mode 100644 index 00000000..b2344bf2 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/is_view_impl.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_IS_VIEW_IMPL_200604227_2150) +#define BOOST_FUSION_IS_VIEW_IMPL_200604227_2150 + +#include <boost/mpl/bool.hpp> + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion +{ + namespace extension + { + template<typename Tag> + struct is_view_impl; + + template<> + struct is_view_impl<example::example_sequence_tag> + : boost::mpl::false_ + {}; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/key_of_impl.hpp b/src/boost/libs/fusion/example/extension/detail/key_of_impl.hpp new file mode 100644 index 00000000..6a7a836d --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/key_of_impl.hpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2009 Christopher Schmidt + + 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) +==============================================================================*/ + +#ifndef BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_KEY_OF_IMPL_HPP +#define BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_KEY_OF_IMPL_HPP + +#include <boost/mpl/if.hpp> + +namespace fields +{ + struct name; + struct age; +} + +namespace example +{ + struct example_struct_iterator_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct key_of_impl; + + template<> + struct key_of_impl<example::example_struct_iterator_tag> + { + template<typename It> + struct apply + : mpl::if_c<!It::index::value, fields::name, fields::age> + {}; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/next_impl.hpp b/src/boost/libs/fusion/example/extension/detail/next_impl.hpp new file mode 100644 index 00000000..8fbaa8b1 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/next_impl.hpp @@ -0,0 +1,46 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_NEXT_IMPL_20060222_1859) +#define BOOST_FUSION_NEXT_IMPL_20060222_1859 + +namespace example +{ + struct example_struct_iterator_tag; + + template<typename Struct, int Pos> + struct example_struct_iterator; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct next_impl; + + template<> + struct next_impl<example::example_struct_iterator_tag> + { + template<typename Iterator> + struct apply + { + typedef typename Iterator::struct_type struct_type; + typedef typename Iterator::index index; + typedef example::example_struct_iterator<struct_type, index::value + 1> type; + + static type + call(Iterator const& i) + { + return type(i.struct_); + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/prior_impl.hpp b/src/boost/libs/fusion/example/extension/detail/prior_impl.hpp new file mode 100644 index 00000000..415692ce --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/prior_impl.hpp @@ -0,0 +1,46 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_PRIOR_IMPL_20060222_1944) +#define BOOST_FUSION_PRIOR_IMPL_20060222_1944 + +namespace example +{ + struct example_struct_iterator_tag; + + template<typename Struct, int Pos> + struct example_struct_iterator; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct prior_impl; + + template<> + struct prior_impl<example::example_struct_iterator_tag> + { + template<typename Iterator> + struct apply + { + typedef typename Iterator::struct_type struct_type; + typedef typename Iterator::index index; + typedef example::example_struct_iterator<struct_type, index::value - 1> type; + + static type + call(Iterator const& i) + { + return type(i.struct_); + } + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/size_impl.hpp b/src/boost/libs/fusion/example/extension/detail/size_impl.hpp new file mode 100644 index 00000000..4dc6ec93 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/size_impl.hpp @@ -0,0 +1,36 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_SIZE_IMPL_20060223_2033) +#define BOOST_FUSION_SIZE_IMPL_20060223_2033 + +#include <boost/mpl/int.hpp> + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct size_impl; + + template<> + struct size_impl<example::example_sequence_tag> + { + template<typename Sequence> + struct apply + : mpl::int_<2> + {}; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/value_at_impl.hpp b/src/boost/libs/fusion/example/extension/detail/value_at_impl.hpp new file mode 100644 index 00000000..6a1d63ef --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/value_at_impl.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_VALUE_AT_IMPL_20060223_2025) +#define BOOST_FUSION_VALUE_AT_IMPL_20060223_2025 + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct value_at_impl; + + template<> + struct value_at_impl<example::example_sequence_tag> + { + template<typename Sequence, typename N> + struct apply; + + template<typename Sequence> + struct apply<Sequence, mpl::int_<0> > + { + typedef std::string type; + }; + + template<typename Sequence> + struct apply<Sequence, mpl::int_<1> > + { + typedef int type; + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/value_at_key_impl.hpp b/src/boost/libs/fusion/example/extension/detail/value_at_key_impl.hpp new file mode 100644 index 00000000..cabc59aa --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/value_at_key_impl.hpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_VALUE_AT_KEY_IMPL_20060223_2025) +#define BOOST_FUSION_VALUE_AT_KEY_IMPL_20060223_2025 + +namespace fields +{ + struct name; + struct age; +} + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct value_at_key_impl; + + template<> + struct value_at_key_impl<example::example_sequence_tag> + { + template<typename Sequence, typename N> + struct apply; + + template<typename Sequence> + struct apply<Sequence, fields::name> + { + typedef std::string type; + }; + + template<typename Sequence> + struct apply<Sequence, fields::age> + { + typedef int type; + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/value_of_data_impl.hpp b/src/boost/libs/fusion/example/extension/detail/value_of_data_impl.hpp new file mode 100644 index 00000000..94cdcc30 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/value_of_data_impl.hpp @@ -0,0 +1,30 @@ +/*============================================================================= + Copyright (c) 2009 Christopher Schmidt + + 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) +==============================================================================*/ + +#ifndef BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_VALUE_OF_DATA_IMPL_HPP +#define BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_VALUE_OF_DATA_IMPL_HPP + +namespace example +{ + struct example_struct_iterator_tag; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct value_of_data_impl; + + template<> + struct value_of_data_impl<example::example_struct_iterator_tag> + : value_of_impl<example::example_struct_iterator_tag> + {}; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/detail/value_of_impl.hpp b/src/boost/libs/fusion/example/extension/detail/value_of_impl.hpp new file mode 100644 index 00000000..6fc7e161 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/detail/value_of_impl.hpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_VALUE_OF_IMPL_20060223_1905) +#define BOOST_FUSION_VALUE_OF_IMPL_20060223_1905 + +#include <string> + +namespace example +{ + struct example_struct_iterator_tag; + + template<typename Struct, int Pos> + struct example_struct_iterator; +} + +namespace boost { namespace fusion { + + namespace extension + { + template<typename Tag> + struct value_of_impl; + + template<> + struct value_of_impl<example::example_struct_iterator_tag> + { + template<typename Iterator> + struct apply; + + template<typename Struct> + struct apply<example::example_struct_iterator<Struct, 0> > + { + typedef std::string type; + }; + + template<typename Struct> + struct apply<example::example_struct_iterator<Struct, 1> > + { + typedef int type; + }; + }; + } +}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/example_struct.hpp b/src/boost/libs/fusion/example/extension/example_struct.hpp new file mode 100644 index 00000000..cbb058f5 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/example_struct.hpp @@ -0,0 +1,25 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_EXAMPLE_STRUCT) +#define BOOST_FUSION_EXAMPLE_STRUCT + +#include "./tag_of.hpp" +#include "./example_struct_iterator.hpp" +#include "./detail/begin_impl.hpp" +#include "./detail/end_impl.hpp" +#include "./detail/at_impl.hpp" +#include "./detail/value_at_impl.hpp" +#include "./detail/size_impl.hpp" +#include "./detail/category_of_impl.hpp" +#include "./detail/at_key_impl.hpp" +#include "./detail/value_at_key_impl.hpp" +#include "./detail/has_key_impl.hpp" +#include "./detail/is_sequence_impl.hpp" +#include "./detail/is_view_impl.hpp" + +#endif diff --git a/src/boost/libs/fusion/example/extension/example_struct_iterator.hpp b/src/boost/libs/fusion/example/extension/example_struct_iterator.hpp new file mode 100644 index 00000000..fa04f085 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/example_struct_iterator.hpp @@ -0,0 +1,70 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_EXAMPLE_STRUCT_ITERATOR) +#define BOOST_FUSION_EXAMPLE_STRUCT_ITERATOR + +#include <boost/fusion/support/iterator_base.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/fusion/support/tag_of_fwd.hpp> +#include <boost/mpl/int.hpp> +#include <boost/type_traits/add_const.hpp> +#include <boost/static_assert.hpp> + +#include "./detail/next_impl.hpp" +#include "./detail/prior_impl.hpp" +#include "./detail/deref_impl.hpp" +#include "./detail/advance_impl.hpp" +#include "./detail/distance_impl.hpp" +#include "./detail/value_of_impl.hpp" +#include "./detail/equal_to_impl.hpp" +#include "./detail/key_of_impl.hpp" +#include "./detail/value_of_data_impl.hpp" +#include "./detail/deref_data_impl.hpp" + +namespace example +{ + struct example_struct_iterator_tag; + + template<typename Struct, int Pos> + struct example_struct_iterator; +} + +namespace boost { namespace fusion { + + namespace traits + { + template<typename Struct, int Pos> + struct tag_of<example::example_struct_iterator<Struct, Pos> > + { + typedef example::example_struct_iterator_tag type; + }; + } +}} + +namespace example { + template<typename Struct, int Pos> + struct example_struct_iterator + : boost::fusion::iterator_base<example_struct_iterator<Struct, Pos> > + { + BOOST_STATIC_ASSERT(Pos >=0 && Pos < 3); + typedef Struct struct_type; + typedef boost::mpl::int_<Pos> index; + + struct category + : boost::fusion::random_access_traversal_tag + , boost::fusion::associative_tag + {}; + + example_struct_iterator(Struct& str) + : struct_(str) {} + + Struct& struct_; + }; +} + +#endif diff --git a/src/boost/libs/fusion/example/extension/example_struct_type.hpp b/src/boost/libs/fusion/example/extension/example_struct_type.hpp new file mode 100644 index 00000000..e1d8e175 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/example_struct_type.hpp @@ -0,0 +1,27 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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_EXAMPLE_STRUCT_TYPE) +#define BOOST_FUSION_EXAMPLE_STRUCT_TYPE + +#include <string> + +namespace example +{ + struct example_struct + { + std::string name; + int age; + example_struct( + const std::string& n, + int a) + : name(n), age(a) + {} + }; +} + +#endif diff --git a/src/boost/libs/fusion/example/extension/tag_of.hpp b/src/boost/libs/fusion/example/extension/tag_of.hpp new file mode 100644 index 00000000..083b730c --- /dev/null +++ b/src/boost/libs/fusion/example/extension/tag_of.hpp @@ -0,0 +1,30 @@ +/*============================================================================= + Copyright (c) 2001-2011 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_20060222_2052) +#define BOOST_FUSION_TAG_OF_20060222_2052 + +#include <boost/fusion/support/tag_of_fwd.hpp> +#include "./example_struct_type.hpp" + +namespace example +{ + struct example_sequence_tag; +} + +namespace boost { namespace fusion { + +namespace traits { + + template<> + struct tag_of<example::example_struct> + { + typedef example::example_sequence_tag type; + }; +}}} + +#endif diff --git a/src/boost/libs/fusion/example/extension/test_example.cpp b/src/boost/libs/fusion/example/extension/test_example.cpp new file mode 100644 index 00000000..581e2300 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/test_example.cpp @@ -0,0 +1,65 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 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) +==============================================================================*/ +#include "./example_struct.hpp" +#include "./example_struct_type.hpp" +#include <boost/detail/lightweight_test.hpp> + +#include <boost/fusion/sequence/intrinsic.hpp> +#include <boost/fusion/support/is_sequence.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/fusion/iterator.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/assert.hpp> + +int main() +{ + example::example_struct bert("bert", 99); + using namespace boost::fusion; + + BOOST_MPL_ASSERT((traits::is_associative<example::example_struct>)); + BOOST_MPL_ASSERT((traits::is_random_access<example::example_struct>)); + BOOST_MPL_ASSERT((traits::is_sequence<example::example_struct>)); + + BOOST_TEST(deref(begin(bert)) == "bert"); + BOOST_TEST(*next(begin(bert)) == 99); + BOOST_TEST(*prior(end(bert)) == 99); + BOOST_TEST(*advance_c<1>(begin(bert)) == 99); + BOOST_TEST(*advance_c<-1>(end(bert)) == 99); + BOOST_TEST(distance(begin(bert), end(bert)) == 2); + + typedef result_of::begin<example::example_struct>::type first; + typedef result_of::next<first>::type second; + BOOST_MPL_ASSERT((boost::is_same<result_of::value_of<first>::type, std::string>)); + BOOST_MPL_ASSERT((boost::is_same<result_of::value_of<second>::type, int>)); + + BOOST_TEST(begin(bert) != end(bert)); + BOOST_TEST(advance_c<2>(begin(bert)) == end(const_cast<const example::example_struct&>(bert))); + + BOOST_TEST(at_c<0>(bert) == "bert"); + BOOST_TEST(at_c<1>(bert) == 99); + + BOOST_TEST(at_key<fields::name>(bert) == "bert"); + BOOST_TEST(at_key<fields::age>(bert) == 99); + + BOOST_TEST(has_key<fields::name>(bert)); + BOOST_TEST(has_key<fields::age>(bert)); + BOOST_TEST(!has_key<int>(bert)); + + BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_c<example::example_struct, 0>::type, std::string>)); + BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_c<example::example_struct, 1>::type, int>)); + + BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::name>::type, std::string>)); + BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::age>::type, int>)); + + BOOST_TEST(deref_data(begin(bert)) == "bert"); + BOOST_TEST(deref_data(next(begin(bert))) == 99); + + BOOST_TEST(size(bert) == 2); + + return boost::report_errors(); +} diff --git a/src/boost/libs/fusion/example/extension/triple.cpp b/src/boost/libs/fusion/example/extension/triple.cpp new file mode 100644 index 00000000..ac8f18e0 --- /dev/null +++ b/src/boost/libs/fusion/example/extension/triple.cpp @@ -0,0 +1,377 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 Nathan Ridge + Copyright (c) 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) +==============================================================================*/ + +/*============================================================================= + An implementation of a std::pair like triple<T0, T1, T2> + We use fusion::sequence_facade and fusion::iterator_facade + to make our triple a fully conforming Boost.Fusion random + traversal sequence. +==============================================================================*/ + +#include <boost/detail/lightweight_test.hpp> + +#include <boost/fusion/sequence/sequence_facade.hpp> +#include <boost/fusion/iterator/iterator_facade.hpp> +#include <boost/fusion/sequence/intrinsic.hpp> +#include <boost/fusion/iterator.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/fusion/algorithm/iteration/fold.hpp> + +#include <boost/mpl/int.hpp> +#include <boost/mpl/identity.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_const.hpp> +#include <boost/type_traits/is_same.hpp> + +#include <string> + +namespace mpl = boost::mpl; +namespace fusion = boost::fusion; + +namespace demo +{ + template<typename Seq, int N> + struct triple_iterator + : fusion::iterator_facade<triple_iterator<Seq, N>, + fusion::random_access_traversal_tag> + { + typedef mpl::int_<N> index; + typedef Seq sequence_type; + + triple_iterator(Seq& seq) + : seq_(seq) {} + + Seq& seq_; + + template<typename T> + struct value_of; + + template<typename Sq> + struct value_of<triple_iterator<Sq, 0> > + : mpl::identity<typename Sq::t0_type> + {}; + + template<typename Sq> + struct value_of<triple_iterator<Sq, 1> > + : mpl::identity<typename Sq::t1_type> + {}; + + template<typename Sq> + struct value_of<triple_iterator<Sq, 2> > + : mpl::identity<typename Sq::t2_type> + {}; + + template<typename T> + struct deref; + + template <typename Sq> + struct deref<triple_iterator<Sq, 0> > + { + typedef typename Sq::t0_type& type; + + static type + call(triple_iterator<Sq, 0> const& iter) + { + return iter.seq_.t0; + } + }; + + template <typename Sq> + struct deref<triple_iterator<Sq, 0> const> + { + typedef typename Sq::t0_type const& type; + + static type + call(triple_iterator<Sq, 0> const& iter) + { + return iter.seq_.t0; + } + }; + + template <typename Sq> + struct deref<triple_iterator<Sq, 1> > + { + typedef typename Sq::t1_type& type; + + static type + call(triple_iterator<Sq, 1> const& iter) + { + return iter.seq_.t1; + } + }; + + template <typename Sq> + struct deref<triple_iterator<Sq, 1> const> + { + typedef typename Sq::t1_type const& type; + + static type + call(triple_iterator<Sq, 1> const& iter) + { + return iter.seq_.t1; + } + }; + + template <typename Sq> + struct deref<triple_iterator<Sq, 2> > + { + typedef typename Sq::t2_type& type; + + static type + call(triple_iterator<Sq, 2> const& iter) + { + return iter.seq_.t2; + } + }; + + template <typename Sq> + struct deref<triple_iterator<Sq, 2> const> + { + typedef typename Sq::t2_type const& type; + + static type + call(triple_iterator<Sq, 2> const& iter) + { + return iter.seq_.t2; + } + }; + + template<typename It> + struct next + { + typedef triple_iterator< + typename It::sequence_type, It::index::value + 1> + type; + + static type call(It const& it) + { + return type(it.seq_); + } + }; + + template<typename It> + struct prior + { + typedef triple_iterator< + typename It::sequence_type, It::index::value - 1> + type; + + static type call(It const& it) + { + return type(it.seq_); + } + }; + + template<typename It1, typename It2> + struct distance + { + typedef typename mpl::minus< + typename It2::index, typename It1::index>::type + type; + + static type call(It1 const& it1, It2 const& it2) + { + return type(); + } + }; + + template<typename It, typename M> + struct advance + { + typedef triple_iterator< + typename It::sequence_type, + It::index::value + M::value> + type; + + static type call(It const& it) + { + return type(it.seq_); + } + }; + }; + + template<typename T0, typename T1, typename T2> + struct triple + : fusion::sequence_facade<triple<T0, T1, T2>, + fusion::random_access_traversal_tag> + { + triple(T0 const& t0, T1 const& t1, T2 const& t2) + : t0(t0), t1(t1), t2(t2) + {} + + template<typename Sq> + struct begin + { + typedef demo::triple_iterator<Sq, 0> type; + + static type call(Sq& sq) + { + return type(sq); + } + }; + + template<typename Sq> + struct end + { + typedef demo::triple_iterator<Sq, 3> type; + + static type call(Sq& sq) + { + return type(sq); + } + }; + + template<typename Sq> + struct size + : mpl::int_<3> + {}; + + template<typename Sq, typename N> + struct value_at + : value_at<Sq, mpl::int_<N::value> > + {}; + + template<typename Sq> + struct value_at<Sq, mpl::int_<0> > + { + typedef typename Sq::t0_type type; + }; + + template<typename Sq> + struct value_at<Sq, mpl::int_<1> > + { + typedef typename Sq::t1_type type; + }; + + template<typename Sq> + struct value_at<Sq, mpl::int_<2> > + { + typedef typename Sq::t2_type type; + }; + + template<typename Sq, typename N> + struct at + : at<Sq, mpl::int_<N::value> > + {}; + + template<typename Sq> + struct at<Sq, mpl::int_<0> > + { + typedef typename + mpl::if_< + boost::is_const<Sq> + , typename Sq::t0_type const& + , typename Sq::t0_type& + >::type + type; + + static type call(Sq& sq) + { + return sq.t0; + } + }; + + template<typename Sq> + struct at<Sq, mpl::int_<1> > + { + typedef typename + mpl::if_< + boost::is_const<Sq> + , typename Sq::t1_type const& + , typename Sq::t1_type& + >::type + type; + + static type call(Sq& sq) + { + return sq.t1; + } + }; + + template<typename Sq> + struct at<Sq, mpl::int_<2> > + { + typedef typename + mpl::if_< + boost::is_const<Sq> + , typename Sq::t2_type const& + , typename Sq::t2_type& + >::type + type; + + static type call(Sq& sq) + { + return sq.t2; + } + }; + + typedef T0 t0_type; + typedef T1 t1_type; + typedef T2 t2_type; + + T0 t0; + T1 t1; + T2 t2; + }; +} + +struct modifying_fold_functor +{ + template <typename T> + struct result + { + typedef bool type; + }; + + template <typename T> + bool operator()(bool b, T&) + { + return b; + } +}; + +struct nonmodifying_fold_functor +{ + template <typename T> + struct result + { + typedef bool type; + }; + + template <typename T> + bool operator()(bool b, const T&) + { + return b; + } +}; + +int main() +{ + typedef demo::triple<int, char, std::string> my_triple; + my_triple t(101, 'a', "hello"); + BOOST_TEST(*fusion::begin(t) == 101); + BOOST_TEST(*fusion::next(fusion::begin(t)) == 'a'); + BOOST_TEST(*fusion::prior(fusion::end(t)) == "hello"); + BOOST_TEST(fusion::distance(fusion::begin(t), fusion::end(t)) == 3); + BOOST_TEST(fusion::size(t) == 3); + BOOST_MPL_ASSERT((boost::is_same< + int, fusion::result_of::value_at_c<my_triple, 0>::type>)); + BOOST_MPL_ASSERT((boost::is_same< + char, fusion::result_of::value_at_c<my_triple, 1>::type>)); + BOOST_MPL_ASSERT((boost::is_same< + std::string, fusion::result_of::value_at_c<my_triple, 2>::type>)); + BOOST_TEST(fusion::at_c<0>(t) == 101); + BOOST_TEST(fusion::at_c<1>(t) == 'a'); + BOOST_TEST(fusion::at_c<2>(t) == "hello"); + BOOST_TEST(fusion::fold(t, true, modifying_fold_functor()) == true); + BOOST_TEST(fusion::fold(t, true, nonmodifying_fold_functor()) == true); + return boost::report_errors(); +} |