From 8aa03299b35e1f3b409456f56fb45d7e20fd70bc Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 5 Sep 2008 04:13:30 +0000 Subject: [PATCH] merged from trunk [SVN r48605] --- include/boost/fusion/include/at_c.hpp | 12 ++++ include/boost/fusion/include/end.hpp | 4 +- .../boost/fusion/sequence/intrinsic/at_c.hpp | 13 +++++ ...uple_forward_ctor.hpp => tuple_expand.hpp} | 19 +++++-- include/boost/fusion/tuple/tuple.hpp | 38 +++++++++---- test/Jamfile | 1 + test/sequence/construction.hpp | 4 +- test/sequence/tr1_tuple_auto_conv.cpp | 56 +++++++++++++++++++ test/sequence/tuple_construction.cpp | 3 +- 9 files changed, 131 insertions(+), 19 deletions(-) create mode 100644 include/boost/fusion/include/at_c.hpp create mode 100644 include/boost/fusion/sequence/intrinsic/at_c.hpp rename include/boost/fusion/tuple/detail/{tuple_forward_ctor.hpp => tuple_expand.hpp} (70%) create mode 100644 test/sequence/tr1_tuple_auto_conv.cpp diff --git a/include/boost/fusion/include/at_c.hpp b/include/boost/fusion/include/at_c.hpp new file mode 100644 index 00000000..a2403d16 --- /dev/null +++ b/include/boost/fusion/include/at_c.hpp @@ -0,0 +1,12 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#if !defined(FUSION_INCLUDE_AT_C) +#define FUSION_INCLUDE_AT_C + +#include + +#endif diff --git a/include/boost/fusion/include/end.hpp b/include/boost/fusion/include/end.hpp index 60be1a98..61d65de0 100644 --- a/include/boost/fusion/include/end.hpp +++ b/include/boost/fusion/include/end.hpp @@ -4,8 +4,8 @@ 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_INCLUDE_BEGIN) -#define FUSION_INCLUDE_BEGIN +#if !defined(FUSION_INCLUDE_END) +#define FUSION_INCLUDE_END #include diff --git a/include/boost/fusion/sequence/intrinsic/at_c.hpp b/include/boost/fusion/sequence/intrinsic/at_c.hpp new file mode 100644 index 00000000..4dc53ae0 --- /dev/null +++ b/include/boost/fusion/sequence/intrinsic/at_c.hpp @@ -0,0 +1,13 @@ +/*============================================================================= + Copyright (c) 2001-2006 Joel de Guzman + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#if !defined(FUSION_AT_C_08252008_0308) +#define FUSION_AT_C_08252008_0308 + +#include + +#endif + diff --git a/include/boost/fusion/tuple/detail/tuple_forward_ctor.hpp b/include/boost/fusion/tuple/detail/tuple_expand.hpp similarity index 70% rename from include/boost/fusion/tuple/detail/tuple_forward_ctor.hpp rename to include/boost/fusion/tuple/detail/tuple_expand.hpp index 2ff20a2a..806515f9 100644 --- a/include/boost/fusion/tuple/detail/tuple_forward_ctor.hpp +++ b/include/boost/fusion/tuple/detail/tuple_expand.hpp @@ -1,19 +1,19 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman - 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) ==============================================================================*/ #ifndef BOOST_PP_IS_ITERATING -#if !defined(FUSION_TUPLE_FORWARD_CTOR_10032005_0815) -#define FUSION_TUPLE_FORWARD_CTOR_10032005_0815 +#if !defined(FUSION_TUPLE_EXPAND_10032005_0815) +#define FUSION_TUPLE_EXPAND_10032005_0815 #include #include #include #define BOOST_PP_FILENAME_1 \ - + #define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_VECTOR_SIZE) #include BOOST_PP_ITERATE() @@ -34,6 +34,17 @@ N, typename detail::call_param::type _)) : base_type(BOOST_PP_ENUM_PARAMS(N, _)) {} + template + tuple(tuple const& rhs) + : base_type(rhs) {} + + template + tuple& operator=(tuple const& rhs) + { + base_type::operator=(rhs); + return *this; + } + #undef N #endif // defined(BOOST_PP_IS_ITERATING) diff --git a/include/boost/fusion/tuple/tuple.hpp b/include/boost/fusion/tuple/tuple.hpp index d9860323..88e28c8e 100644 --- a/include/boost/fusion/tuple/tuple.hpp +++ b/include/boost/fusion/tuple/tuple.hpp @@ -1,7 +1,7 @@ /*============================================================================= Copyright (c) 2005 Joel de Guzman - 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_TUPLE_10032005_0810) @@ -16,6 +16,7 @@ #include #include #include +#include namespace boost { namespace fusion { @@ -23,35 +24,50 @@ namespace boost { namespace fusion struct tuple : vector { typedef vector< - BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, T)> + BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, T)> base_type; tuple() : base_type() {} - - template - tuple(Sequence const& rhs) + + tuple(tuple const& rhs) : base_type(rhs) {} - #include + template + tuple(std::pair const& rhs) + : base_type(rhs) {} + + #include template - tuple& - operator=(T const& rhs) + tuple& operator=(T const& rhs) + { + base_type::operator=(rhs); + return *this; + } + + tuple& operator=(tuple const& rhs) + { + base_type::operator=(rhs); + return *this; + } + + template + tuple& operator=(std::pair const& rhs) { base_type::operator=(rhs); return *this; } }; - template + template struct tuple_size : result_of::size {}; - template + template struct tuple_element : result_of::value_at_c {}; template - inline typename + inline typename lazy_disable_if< is_const , result_of::at_c diff --git a/test/Jamfile b/test/Jamfile index b6101e3d..12407035 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -89,6 +89,7 @@ import testing ; [ run sequence/tuple_misc.cpp : : : : ] [ run sequence/tuple_mutate.cpp : : : : ] [ run sequence/tuple_tie.cpp : : : : ] + [ run sequence/tr1_tuple_auto_conv.cpp : : : : ] [ run sequence/transform_view.cpp : : : : ] [ run sequence/vector_comparison.cpp : : : : ] [ run sequence/vector_construction.cpp : : : : ] diff --git a/test/sequence/construction.hpp b/test/sequence/construction.hpp index c667b1a4..5c6abdf2 100644 --- a/test/sequence/construction.hpp +++ b/test/sequence/construction.hpp @@ -2,7 +2,7 @@ Copyright (c) 1999-2003 Jaakko Jarvi Copyright (c) 2001-2006 Joel de Guzman - 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) ==============================================================================*/ #include @@ -57,7 +57,9 @@ test() FUSION_SEQUENCE<> empty0; +#ifndef TR1_TUPLE_TEST FUSION_SEQUENCE<> empty1(empty); +#endif FUSION_SEQUENCE t1; BOOST_TEST(FUSION_AT<0>(t1) == int()); diff --git a/test/sequence/tr1_tuple_auto_conv.cpp b/test/sequence/tr1_tuple_auto_conv.cpp new file mode 100644 index 00000000..0c20fa3f --- /dev/null +++ b/test/sequence/tr1_tuple_auto_conv.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +namespace Core +{ + class AutoConverter + { + std::tr1::shared_ptr t_; + + public: + AutoConverter(std::tr1::shared_ptr const & t) + : t_(t) + {} + + template + operator C () + { + try + { + boost::any & a = (*t_); + + return boost::any_cast(a); + } + catch(boost::bad_any_cast & e) + { + std::cerr << "Internal conversion bug: " + << "Failed to convert data holder to " + << typeid(C).name() << "\n" + << e.what() + << std::endl; + + C c = C(); + return c; + } + } + }; + + + inline AutoConverter Demo() + { + std::tr1::shared_ptr p_result + (new boost::any(std::tr1::make_tuple(1, 2, 3, 4))); + return p_result; + } + +} // namespace Core + + +int main(int argc, char* argv[]) +{ + std::tr1::tuple test = Core::Demo(); + return 0; +} + diff --git a/test/sequence/tuple_construction.cpp b/test/sequence/tuple_construction.cpp index 7f025d51..ec602abb 100644 --- a/test/sequence/tuple_construction.cpp +++ b/test/sequence/tuple_construction.cpp @@ -2,12 +2,13 @@ Copyright (c) 1999-2003 Jaakko Jarvi Copyright (c) 2001-2006 Joel de Guzman - 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) ==============================================================================*/ #include #include +#define TR1_TUPLE_TEST #define FUSION_SEQUENCE tuple #define FUSION_AT get #include "construction.hpp"