diff --git a/include/boost/fusion/adapted/array/at_impl.hpp b/include/boost/fusion/adapted/array/at_impl.hpp new file mode 100644 index 00000000..12f03726 --- /dev/null +++ b/include/boost/fusion/adapted/array/at_impl.hpp @@ -0,0 +1,38 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_AT_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_AT_IMPL_HPP + +#include +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct at_impl; + + template<> + struct at_impl + { + template + struct apply + { + typedef typename + add_reference::type>::type + type; + + static type + call(Seq& seq) + { + return seq[N::value]; + } + }; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/begin_impl.hpp b/include/boost/fusion/adapted/array/begin_impl.hpp new file mode 100644 index 00000000..2ee4d707 --- /dev/null +++ b/include/boost/fusion/adapted/array/begin_impl.hpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_BEGIN_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_BEGIN_IMPL_HPP + +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct begin_impl; + + template <> + struct begin_impl + { + template + struct apply + { + typedef + basic_iterator< + po_array_iterator_tag + , random_access_traversal_tag + , Seq + , 0 + > + type; + + static type + call(Seq& seq) + { + return type(seq,0); + } + }; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/category_of_impl.hpp b/include/boost/fusion/adapted/array/category_of_impl.hpp new file mode 100644 index 00000000..0a633a45 --- /dev/null +++ b/include/boost/fusion/adapted/array/category_of_impl.hpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_CATEGORY_OF_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_CATEGORY_OF_IMPL_HPP + +namespace boost { namespace fusion +{ + struct random_access_traversal_tag; + + namespace extension + { + template + struct category_of_impl; + + template<> + struct category_of_impl + { + template + struct apply + { + typedef random_access_traversal_tag type; + }; + }; + } +}} + +#endif diff --git a/include/boost/fusion/adapted/array/deref_impl.hpp b/include/boost/fusion/adapted/array/deref_impl.hpp new file mode 100644 index 00000000..a58cf990 --- /dev/null +++ b/include/boost/fusion/adapted/array/deref_impl.hpp @@ -0,0 +1,40 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_DEREF_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_DEREF_IMPL_HPP + +#include +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct deref_impl; + + template <> + struct deref_impl + { + template + struct apply + { + typedef typename + add_reference< + typename remove_extent::type + >::type + type; + + static type + call(It const& it) + { + return (*it.seq)[It::index::value]; + } + }; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/end_impl.hpp b/include/boost/fusion/adapted/array/end_impl.hpp new file mode 100644 index 00000000..5b367f9c --- /dev/null +++ b/include/boost/fusion/adapted/array/end_impl.hpp @@ -0,0 +1,44 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_END_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_END_IMPL_HPP + +#include +#include +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct end_impl; + + template <> + struct end_impl + { + template + struct apply + { + typedef + basic_iterator< + po_array_iterator_tag + , random_access_traversal_tag + , Seq + , extent::value-1>::value + > + type; + + static type + call(Seq& seq) + { + return type(seq,0); + } + }; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/is_sequence_impl.hpp b/include/boost/fusion/adapted/array/is_sequence_impl.hpp new file mode 100644 index 00000000..d6de8585 --- /dev/null +++ b/include/boost/fusion/adapted/array/is_sequence_impl.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_IS_SEQUENCE_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_IS_SEQUENCE_IMPL_HPP + +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct is_sequence_impl; + + template<> + struct is_sequence_impl + { + template + struct apply + : mpl::true_ + {}; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/is_view_impl.hpp b/include/boost/fusion/adapted/array/is_view_impl.hpp new file mode 100644 index 00000000..238eac0e --- /dev/null +++ b/include/boost/fusion/adapted/array/is_view_impl.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_IS_VIEW_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_IS_VIEW_IMPL_HPP + +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct is_view_impl; + + template<> + struct is_view_impl + { + template + struct apply + : mpl::false_ + {}; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/size_impl.hpp b/include/boost/fusion/adapted/array/size_impl.hpp new file mode 100644 index 00000000..8be5a29d --- /dev/null +++ b/include/boost/fusion/adapted/array/size_impl.hpp @@ -0,0 +1,29 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_SIZE_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_SIZE_IMPL_HPP + +#include +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct size_impl; + + template<> + struct size_impl + { + template + struct apply + : extent::value-1> + {}; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/tag_of.hpp b/include/boost/fusion/adapted/array/tag_of.hpp index 67a4f116..7c732a70 100644 --- a/include/boost/fusion/adapted/array/tag_of.hpp +++ b/include/boost/fusion/adapted/array/tag_of.hpp @@ -1,58 +1,72 @@ /*============================================================================= - Copyright (c) 2001-2006 Joel de Guzman - Copyright (c) 2005-2006 Dan Marsden + Copyright (c) 2010 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) ==============================================================================*/ -#if !defined(FUSION_SEQUENCE_TAG_OF_27122005_1030) -#define FUSION_SEQUENCE_TAG_OF_27122005_1030 + +#ifndef BOOST_FUSION_ADAPTED_ARRAY_TAG_OF_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_TAG_OF_HPP #include - #include -namespace boost -{ - template - class array; -} - -namespace boost { namespace fusion +namespace boost { - struct array_tag; - struct fusion_sequence_tag; - - namespace traits + namespace fusion { - template -#if defined(BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS) - struct tag_of, void > -#else - struct tag_of > -#endif + struct po_array_tag; + struct po_array_iterator_tag; + struct random_access_traversal_tag; + struct fusion_sequence_tag; + + namespace traits { - typedef array_tag type; +#ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS + template + struct tag_of + { + typedef po_array_tag type; + }; + + template + struct tag_of + { + typedef po_array_tag type; + }; +#else + template + struct tag_of + { + typedef po_array_tag type; + }; + + template + struct tag_of + { + typedef po_array_tag type; + }; +#endif + } + } + + namespace mpl + { + template + struct sequence_tag; + + template + struct sequence_tag + { + typedef fusion::po_array_tag type; + }; + + template + struct sequence_tag + { + typedef fusion::po_array_tag type; }; } -}} - -namespace boost { namespace mpl -{ - template - struct sequence_tag; - - template - struct sequence_tag > - { - typedef fusion::fusion_sequence_tag type; - }; - - template - struct sequence_tag const> - { - typedef fusion::fusion_sequence_tag type; - }; -}} +} #endif diff --git a/include/boost/fusion/adapted/array/value_at_impl.hpp b/include/boost/fusion/adapted/array/value_at_impl.hpp new file mode 100644 index 00000000..4e04c37a --- /dev/null +++ b/include/boost/fusion/adapted/array/value_at_impl.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_VALUE_AT_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_VALUE_AT_IMPL_HPP + +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct value_at_impl; + + template <> + struct value_at_impl + { + template + struct apply + : remove_extent + {}; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/value_of_impl.hpp b/include/boost/fusion/adapted/array/value_of_impl.hpp new file mode 100644 index 00000000..2bbddf23 --- /dev/null +++ b/include/boost/fusion/adapted/array/value_of_impl.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2010 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_ADAPTED_ARRAY_VALUE_OF_IMPL_HPP +#define BOOST_FUSION_ADAPTED_ARRAY_VALUE_OF_IMPL_HPP + +#include + +namespace boost { namespace fusion { namespace extension +{ + template + struct value_of_impl; + + template <> + struct value_of_impl + { + template + struct apply + : remove_extent + {}; + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/array/array_iterator.hpp b/include/boost/fusion/adapted/boost_array/array_iterator.hpp similarity index 100% rename from include/boost/fusion/adapted/array/array_iterator.hpp rename to include/boost/fusion/adapted/boost_array/array_iterator.hpp diff --git a/include/boost/fusion/adapted/array/detail/at_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/at_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/at_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/at_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/begin_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/begin_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/begin_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/begin_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/category_of_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/category_of_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/category_of_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/category_of_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/end_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/end_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/end_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/end_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/is_sequence_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/is_sequence_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/is_sequence_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/is_sequence_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/is_view_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/is_view_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/is_view_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/is_view_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/size_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/size_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/size_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/size_impl.hpp diff --git a/include/boost/fusion/adapted/array/detail/value_at_impl.hpp b/include/boost/fusion/adapted/boost_array/detail/value_at_impl.hpp similarity index 100% rename from include/boost/fusion/adapted/array/detail/value_at_impl.hpp rename to include/boost/fusion/adapted/boost_array/detail/value_at_impl.hpp diff --git a/include/boost/fusion/adapted/boost_array/tag_of.hpp b/include/boost/fusion/adapted/boost_array/tag_of.hpp new file mode 100644 index 00000000..67a4f116 --- /dev/null +++ b/include/boost/fusion/adapted/boost_array/tag_of.hpp @@ -0,0 +1,58 @@ +/*============================================================================= + 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(FUSION_SEQUENCE_TAG_OF_27122005_1030) +#define FUSION_SEQUENCE_TAG_OF_27122005_1030 + +#include + +#include + +namespace boost +{ + template + class array; +} + +namespace boost { namespace fusion +{ + struct array_tag; + struct fusion_sequence_tag; + + namespace traits + { + template +#if defined(BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS) + struct tag_of, void > +#else + struct tag_of > +#endif + { + typedef array_tag type; + }; + } +}} + +namespace boost { namespace mpl +{ + template + struct sequence_tag; + + template + struct sequence_tag > + { + typedef fusion::fusion_sequence_tag type; + }; + + template + struct sequence_tag const> + { + typedef fusion::fusion_sequence_tag type; + }; +}} + +#endif diff --git a/test/sequence/array.cpp b/test/sequence/array.cpp new file mode 100644 index 00000000..15b4ed89 --- /dev/null +++ b/test/sequence/array.cpp @@ -0,0 +1,39 @@ +/*============================================================================= + Copyright (c) 2010 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) +==============================================================================*/ + +#include + +#include +#include +#include +#include +#include + +#include + +int main() +{ + using namespace boost::fusion; + typedef int array_type[3]; + + BOOST_MPL_ASSERT((traits::is_sequence)); + BOOST_MPL_ASSERT_NOT((traits::is_view)); + + array_type arr = {1,2,3}; + + BOOST_TEST(*begin(arr) == 1); + BOOST_TEST(*next(begin(arr)) == 2); + BOOST_TEST(*advance_c<2>(begin(arr)) == 3); + BOOST_TEST(prior(next(begin(arr))) == begin(arr)); + BOOST_TEST(*prior(end(arr)) == 3); + BOOST_TEST(at_c<2>(arr) == 3); + BOOST_TEST(size(arr) == 3); + BOOST_TEST(distance(begin(arr), end(arr)) == 3); + + return boost::report_errors(); +} +