From 473b86293ba0c116f865849af660361558b45f1e Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 7 Sep 2014 16:25:48 +0200 Subject: [PATCH 01/10] Added rvalue reference, perfect forwarding and variadic template support --- include/boost/assign/assignment_exception.hpp | 6 +- include/boost/assign/list_inserter.hpp | 98 +++++++++++++++++- include/boost/assign/list_of.hpp | 144 ++++++++++++++++++++++++-- include/boost/assign/ptr_list_inserter.hpp | 26 +++++ include/boost/assign/ptr_list_of.hpp | 86 ++++++++++----- include/boost/assign/ptr_map_inserter.hpp | 27 ++++- include/boost/assign/std/deque.hpp | 15 ++- include/boost/assign/std/list.hpp | 15 ++- include/boost/assign/std/queue.hpp | 19 ++++ include/boost/assign/std/set.hpp | 23 +++- include/boost/assign/std/slist.hpp | 13 ++- include/boost/assign/std/stack.hpp | 14 ++- include/boost/assign/std/vector.hpp | 14 ++- 13 files changed, 450 insertions(+), 50 deletions(-) diff --git a/include/boost/assign/assignment_exception.hpp b/include/boost/assign/assignment_exception.hpp index 96ea417..21b6e3a 100644 --- a/include/boost/assign/assignment_exception.hpp +++ b/include/boost/assign/assignment_exception.hpp @@ -28,12 +28,12 @@ namespace boost assignment_exception( const char* _what ) : what_( _what ) { } - - virtual const char* what() const throw() + + virtual const char* what() const BOOST_NOEXCEPT_OR_NOTHROW { return what_; } - + private: const char* what_; }; diff --git a/include/boost/assign/list_inserter.hpp b/include/boost/assign/list_inserter.hpp index 46d572c..50dafb5 100644 --- a/include/boost/assign/list_inserter.hpp +++ b/include/boost/assign/list_inserter.hpp @@ -22,14 +22,19 @@ #include #include #include +#include #include +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #include #include #include #include #include +#endif + namespace boost { namespace assign_detail @@ -62,11 +67,19 @@ namespace assign_detail call_push_back( C& c ) : c_( c ) { } +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > void operator()( T r ) { c_.push_back( r ); } +#else + template< class T > + void operator()(T&& r) + { + c_.push_back(boost::forward(r)); + } +#endif }; template< class C > @@ -76,12 +89,20 @@ namespace assign_detail public: call_push_front( C& c ) : c_( c ) { } - + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > void operator()( T r ) { c_.push_front( r ); } +#else + template< class T > + void operator()(T&& r) + { + c_.push_front(boost::forward(r)); + } +#endif }; template< class C > @@ -92,11 +113,19 @@ namespace assign_detail call_push( C& c ) : c_( c ) { } +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > void operator()( T r ) { c_.push( r ); } +#else + template< class T > + void operator()(T&& r) + { + c_.push(boost::forward(r)); + } +#endif }; template< class C > @@ -106,12 +135,20 @@ namespace assign_detail public: call_insert( C& c ) : c_( c ) { } - + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > void operator()( T r ) { c_.insert( r ); } +#else + template< class T > + void operator()(T&& r) + { + c_.insert(boost::forward(r)); + } +#endif }; template< class C > @@ -186,14 +223,23 @@ namespace assign insert_( Argument() ); return *this; } - + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > list_inserter& operator=( const T& r ) { insert_( r ); return *this; } - +#else + template< class T > + list_inserter& operator=( T&& r ) + { + insert_(boost::forward(r)); + return *this; + } +#endif + template< class T > list_inserter& operator=( assign_detail::repeater r ) { @@ -206,12 +252,21 @@ namespace assign return operator,( r ); } +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > list_inserter& operator,( const T& r ) { insert_( r ); return *this; } +#else + template< class T > + list_inserter& operator,(T&& r) + { + insert_( boost::forward(r) ); + return *this; + } +#endif #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) template< class T > @@ -266,6 +321,7 @@ namespace assign return range( boost::begin(r), boost::end(r) ); } +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > list_inserter& operator()( const T& t ) { @@ -316,6 +372,36 @@ namespace assign #include BOOST_PP_LOCAL_ITERATE() +#else + template< class... Ts > + list_inserter& operator()(Ts&&... ts) + { + insert(arg_type(), boost::forward(ts)...); + return *this; + } + + template< class T > + void insert(single_arg_type, T&& t) + { + // Special implementation for single argument overload to prevent accidental casts (type-cast using functional notation) + // Use static_cast for single argument to prevent accidental casts (type-cast using functional notation) + Argument a(boost::forward(t)); + insert_(boost::move(a)); + } + + template< class T1, class T2, class... Ts > + void insert(single_arg_type, T1&& t1, T2&& t2, Ts&&... ts) + { + insert_(Argument(boost::forward(t1), boost::forward(t2), boost::forward(ts)...)); + } + + template< class... Ts > + void insert(n_arg_type, Ts&&... ts) + { + insert_(boost::forward(ts)...); + } + +#endif Function fun_private() const { @@ -392,9 +478,13 @@ namespace assign } // namespace 'assign' } // namespace 'boost' +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #undef BOOST_ASSIGN_PARAMS1 #undef BOOST_ASSIGN_PARAMS2 #undef BOOST_ASSIGN_PARAMS3 #undef BOOST_ASSIGN_MAX_PARAMETERS #endif + +#endif diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index 5b995fd..f32c65c 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -28,14 +28,19 @@ #include #include #include +#include #include #include #include +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #include #include #include +#endif + #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // BCB requires full type definition for is_array<> to work correctly. #include @@ -59,6 +64,7 @@ namespace assign_detail template< class T > struct assign_decay { +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) // // Add constness to array parameters // to support string literals properly @@ -67,6 +73,25 @@ namespace assign_detail ::boost::is_array, ::boost::decay, ::boost::decay >::type type; + +#else + private: + // + // Add constness to array parameters + // to support string literals properly + // + typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< + ::boost::is_array, + ::boost::decay, + ::boost::decay >::type Ty; + + public: + // boost::decay does not remove cv from class types + typedef BOOST_DEDUCED_TYPENAME mpl::if_c< + ::boost::is_pointer::value, + Ty, + BOOST_DEDUCED_TYPENAME ::boost::remove_cv::type>::type type; +#endif }; template< class T, std::size_t sz > @@ -352,8 +377,12 @@ namespace assign_detail size_type size() const { return values_.size(); } private: +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) void push_back( value_type r ) { values_.push_back( r ); } - +#else + void push_back( const value_type& r ) { values_.push_back( r ); } + void push_back( value_type&& r ) { values_.push_back( boost::move( r ) ); } +#endif public: generic_list& operator,( const Ty& u ) { @@ -361,19 +390,37 @@ namespace assign_detail return *this; } - generic_list& operator()() +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + + generic_list& operator,( Ty&& u ) { - this->push_back( Ty() ); + this->push_back( boost::move(u) ); return *this; } - - generic_list& operator()( const Ty& u ) +#endif + generic_list& operator()(Ty const& u) { this->push_back( u ); return *this; } - - + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + + generic_list& operator()(Ty&& u) + { + this->push_back( boost::move(u) ); + return *this; + } +#endif + + generic_list& operator()() + { + this->push_back( Ty() ); + return *this; + } + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value #define BOOST_ASSIGN_MAX_PARAMS 5 #endif @@ -396,6 +443,14 @@ namespace assign_detail #include BOOST_PP_LOCAL_ITERATE() +#else + template< class U0, class U1, class... Us > + generic_list& operator()(U0&& u0, U1&& u1, Us&&... us) + { + this->push_back(Ty(boost::forward(u0), boost::forward(u1), boost::forward(us)...)); + return *this; + } +#endif template< class U > generic_list& repeat( std::size_t sz, U u ) @@ -590,12 +645,14 @@ namespace assign_detail namespace assign { template< class T > - inline assign_detail::generic_list + inline assign_detail::generic_list::type> list_of() { - return assign_detail::generic_list()( T() ); + assign_detail::generic_list::type> gl; + gl(); + return gl; } - +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > inline assign_detail::generic_list list_of( const T& t ) @@ -603,6 +660,17 @@ namespace assign return assign_detail::generic_list()( t ); } +#else + template< class T > + inline assign_detail::generic_list::type> + list_of(T&& t) + { + assign_detail::generic_list::type> gl; + gl(boost::forward(t)); + return gl; + } +#endif + template< int N, class T > inline assign_detail::static_generic_list< BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type,N> ref_list_of( T& t ) @@ -617,6 +685,8 @@ namespace assign return assign_detail::static_generic_list::type,N>( t ); } +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) #define BOOST_PP_LOCAL_MACRO(n) \ template< class T, class U, BOOST_ASSIGN_PARAMS1(n) > \ @@ -641,7 +711,29 @@ namespace assign #include BOOST_PP_LOCAL_ITERATE() +#else + template< class T, class U, class... Us > + inline assign_detail::generic_list::type> + list_of(U&& u, Us&&... us) + { + assign_detail::generic_list::type> gl; + gl(boost::forward(u), boost::forward(us)...); + return gl; + } + + template< class U, class... Us > + inline assign_detail::generic_list< tuple > + tuple_list_of(U u, Us... us) + { + assign_detail::generic_list< tuple > gl; + gl(tuple(u, us...)); + return gl; + } +#endif + + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class Key, class T > inline assign_detail::generic_list< std::pair < @@ -665,12 +757,39 @@ namespace assign { return map_list_of( f, s ); } +#else + template< class Key, class T > + inline assign_detail::generic_list< std::pair + < + BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type, + BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type + > > + map_list_of( Key&& k, T&& t ) + { + typedef BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type k_type; + typedef BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type t_type; + assign_detail::generic_list< std::pair > gl; + gl(boost::forward(k), boost::forward(t)); + return gl; + } - + template< class F, class S > + inline assign_detail::generic_list< std::pair + < + BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type, + BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type + > > + pair_list_of( F&& f, S&& s) + { + return map_list_of(boost::forward(f), boost::forward(s)); + } +#endif } // namespace 'assign' } // namespace 'boost' +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #undef BOOST_ASSIGN_PARAMS1 #undef BOOST_ASSIGN_PARAMS2 #undef BOOST_ASSIGN_PARAMS3 @@ -679,3 +798,6 @@ namespace assign #undef BOOST_ASSIGN_MAX_PARAMETERS #endif + + +#endif diff --git a/include/boost/assign/ptr_list_inserter.hpp b/include/boost/assign/ptr_list_inserter.hpp index 20741f2..55f6e56 100644 --- a/include/boost/assign/ptr_list_inserter.hpp +++ b/include/boost/assign/ptr_list_inserter.hpp @@ -18,6 +18,15 @@ #include #include #include +#include + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +#include +#include +#include + +#endif namespace boost { @@ -44,6 +53,8 @@ namespace assign ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ ) {} + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) ptr_list_inserter& operator()() { insert_( new obj_type() ); @@ -77,6 +88,17 @@ namespace assign #include BOOST_PP_LOCAL_ITERATE() +#else + + template< class... Ts > + ptr_list_inserter& operator()(Ts&&... ts) + { + insert_(new obj_type(boost::forward(ts)...)); + return *this; + } + +#endif + private: ptr_list_inserter& operator=( const ptr_list_inserter& ); @@ -156,9 +178,13 @@ namespace assign } // namespace 'assign' } // namespace 'boost' +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #undef BOOST_ASSIGN_PARAMS1 #undef BOOST_ASSIGN_PARAMS2 #undef BOOST_ASSIGN_PARAMS3 #undef BOOST_ASSIGN_MAX_PARAMETERS #endif + +#endif diff --git a/include/boost/assign/ptr_list_of.hpp b/include/boost/assign/ptr_list_of.hpp index 0ea6cd2..33cb8a9 100644 --- a/include/boost/assign/ptr_list_of.hpp +++ b/include/boost/assign/ptr_list_of.hpp @@ -26,11 +26,16 @@ #include #include #include +#include + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #include #include #include +#endif + namespace boost { @@ -38,18 +43,18 @@ namespace assign_detail { ///////////////////////////////////////////////////////////////////////// // Part 1: flexible and efficient interface - ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// - template< class T > - class generic_ptr_list : + template< class T > + class generic_ptr_list : public converter< generic_ptr_list, - BOOST_DEDUCED_TYPENAME boost::ptr_vector::iterator > + BOOST_DEDUCED_TYPENAME boost::ptr_vector::iterator > { protected: typedef boost::ptr_vector impl_type; typedef std::auto_ptr release_type; mutable impl_type values_; - + public: typedef BOOST_DEDUCED_TYPENAME impl_type::iterator iterator; typedef iterator const_iterator; @@ -67,7 +72,7 @@ namespace assign_detail { return values_.release(); } - + public: iterator begin() const { return values_.begin(); } iterator end() const { return values_.end(); } @@ -78,12 +83,12 @@ namespace assign_detail operator impl_type() const { - return values_; + return values_; } - + template< template class Seq, class U, - class CA, class A > - operator Seq() const + class CA, class A > + operator Seq() const { Seq result; result.transfer( result.end(), values_ ); @@ -96,7 +101,7 @@ namespace assign_detail { std::auto_ptr res( new PtrContainer() ); while( !empty() ) - res->insert( res->end(), + res->insert( res->end(), values_.pop_back().release() ); return res; } @@ -104,13 +109,15 @@ namespace assign_detail template< class PtrContainer > std::auto_ptr to_container( const PtrContainer& c ) const { - return convert( &c ); + return convert( &c ); } - + protected: void push_back( T* r ) { values_.push_back( r ); } - + public: +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + generic_ptr_list& operator()() { this->push_back( new T() ); @@ -123,12 +130,12 @@ namespace assign_detail this->push_back( new T(u) ); return *this; } - - + + #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value #define BOOST_ASSIGN_MAX_PARAMS 5 -#endif -#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) +#endif +#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U) #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u) #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u) @@ -142,27 +149,44 @@ namespace assign_detail return *this; \ } \ /**/ - + #include BOOST_PP_LOCAL_ITERATE() +#else + template< class... Us > + generic_ptr_list& operator()(Us&&... us) + { + this->push_back(new T(boost::forward(us)...)); + return *this; + } +#endif + + + }; // class 'generic_ptr_list' } // namespace 'assign_detail' namespace assign { +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template< class T > inline assign_detail::generic_ptr_list ptr_list_of() { - return assign_detail::generic_ptr_list()(); + assign_detail::generic_ptr_list gpl; + gpl(); + return gpl; } - + template< class T, class U > - inline assign_detail::generic_ptr_list + inline assign_detail::generic_ptr_list ptr_list_of( const U& t ) { - return assign_detail::generic_ptr_list()( t ); + assign_detail::generic_ptr_list gpl; + gpl( t ); + return gpl; } @@ -175,13 +199,25 @@ namespace assign return assign_detail::generic_ptr_list()(u, BOOST_ASSIGN_PARAMS3(n)); \ } \ /**/ - + #include BOOST_PP_LOCAL_ITERATE() +#else + template< class T, class... Us > + inline assign_detail::generic_ptr_list + ptr_list_of(Us&&... us) + { + assign_detail::generic_ptr_list gpl; + gpl(boost::forward(us)...); + return gpl; + } + +#endif } // namespace 'assign' } // namespace 'boost' +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #undef BOOST_ASSIGN_PARAMS1 #undef BOOST_ASSIGN_PARAMS2 @@ -189,3 +225,5 @@ namespace assign #undef BOOST_ASSIGN_MAX_PARAMETERS #endif + +#endif diff --git a/include/boost/assign/ptr_map_inserter.hpp b/include/boost/assign/ptr_map_inserter.hpp index fb180f2..3445270 100644 --- a/include/boost/assign/ptr_map_inserter.hpp +++ b/include/boost/assign/ptr_map_inserter.hpp @@ -18,6 +18,15 @@ #include #include #include +#include + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +#include +#include +#include + +#endif namespace boost { @@ -38,7 +47,9 @@ namespace assign ptr_map_inserter( PtrMap& m ) : m_( m ) {} - + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template< class Key > ptr_map_inserter& operator()( const Key& t ) { @@ -68,6 +79,16 @@ namespace assign #include BOOST_PP_LOCAL_ITERATE() +#else + template< class Key, class... Ts > + ptr_map_inserter& operator()(Key&& k, Ts&&... ts) + { + key_type key(boost::forward(k)); + m_.insert(boost::move(key), new obj_type(boost::forward(ts)...)); + return *this; + } + +#endif private: ptr_map_inserter& operator=( const ptr_map_inserter& ); @@ -95,9 +116,13 @@ namespace assign } // namespace 'assign' } // namespace 'boost' +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + #undef BOOST_ASSIGN_PARAMS1 #undef BOOST_ASSIGN_PARAMS2 #undef BOOST_ASSIGN_PARAMS3 #undef BOOST_ASSIGN_MAX_PARAMETERS #endif + +#endif diff --git a/include/boost/assign/std/deque.hpp b/include/boost/assign/std/deque.hpp index f808b70..b357aa6 100644 --- a/include/boost/assign/std/deque.hpp +++ b/include/boost/assign/std/deque.hpp @@ -18,12 +18,14 @@ #include #include +#include #include namespace boost { namespace assign { +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class V, class A, class V2 > inline list_inserter< assign_detail::call_push_back< std::deque >, V > @@ -31,7 +33,18 @@ namespace assign { return push_back( c )( v ); } - + +#else + + template< class V, class A, class V2 > + inline list_inserter< assign_detail::call_push_back< std::deque >, V > + operator+=(std::deque& c, V2&& v) + { + return push_back(c)(boost::forward(v)); + } + +#endif + } } diff --git a/include/boost/assign/std/list.hpp b/include/boost/assign/std/list.hpp index 439006d..3415a35 100644 --- a/include/boost/assign/std/list.hpp +++ b/include/boost/assign/std/list.hpp @@ -18,12 +18,14 @@ #include #include +#include #include namespace boost { namespace assign { +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class V, class A, class V2 > inline list_inserter< assign_detail::call_push_back< std::list >, V > @@ -31,7 +33,18 @@ namespace assign { return push_back( c )( v ); } - + +#else + + template< class V, class A, class V2 > + inline list_inserter< assign_detail::call_push_back< std::list >, V > + operator+=(std::list& c, V2&& v) + { + return push_back(c)(boost::forward(v)); + } + +#endif + } } diff --git a/include/boost/assign/std/queue.hpp b/include/boost/assign/std/queue.hpp index d6023e8..009dc20 100644 --- a/include/boost/assign/std/queue.hpp +++ b/include/boost/assign/std/queue.hpp @@ -18,12 +18,14 @@ #include #include +#include #include namespace boost { namespace assign { +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class V, class C, class V2 > inline list_inserter< assign_detail::call_push< std::queue >, V > @@ -39,6 +41,23 @@ namespace assign return push( c )( v ); } +#else + + template< class V, class C, class V2 > + inline list_inserter< assign_detail::call_push< std::queue >, V > + operator+=(std::queue& c, V2&& v) + { + return push(c)(boost::forward(v)); + } + + template< class V, class C, class V2 > + inline list_inserter< assign_detail::call_push< std::priority_queue >, V > + operator+=(std::priority_queue& c, V2&& v) + { + return push(c)(boost::forward(v)); + } + +#endif } } diff --git a/include/boost/assign/std/set.hpp b/include/boost/assign/std/set.hpp index e4d5ee2..0aefbee 100644 --- a/include/boost/assign/std/set.hpp +++ b/include/boost/assign/std/set.hpp @@ -18,12 +18,16 @@ #include #include +#include #include namespace boost { namespace assign { + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template< class K, class C, class A, class K2 > inline list_inserter< assign_detail::call_insert< std::set >, K > operator+=( std::set& c, K2 k ) @@ -37,7 +41,24 @@ namespace assign { return insert( c )( k ); } - + +#else + + template< class K, class C, class A, class K2 > + inline list_inserter< assign_detail::call_insert< std::set >, K > + operator+=(std::set& c, K2&& k) + { + return insert(c)(boost::forward(k)); + } + + template< class K, class C, class A, class K2 > + inline list_inserter< assign_detail::call_insert< std::multiset >, K > + operator+=(std::multiset& c, K2&& k) + { + return insert(c)(boost::forward(k)); + } + +#endif } } diff --git a/include/boost/assign/std/slist.hpp b/include/boost/assign/std/slist.hpp index 0704b23..ac1f48a 100644 --- a/include/boost/assign/std/slist.hpp +++ b/include/boost/assign/std/slist.hpp @@ -19,6 +19,7 @@ #endif #include +#include #ifdef BOOST_SLIST_HEADER # include BOOST_SLIST_HEADER #else @@ -29,14 +30,22 @@ namespace boost { namespace assign { - +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class V, class A, class V2 > inline list_inserter< assign_detail::call_push_back< BOOST_STD_EXTENSION_NAMESPACE::slist >, V > operator+=( BOOST_STD_EXTENSION_NAMESPACE::slist& c, V2 v ) { return push_back( c )( v ); } - +#else + template< class V, class A, class V2 > + inline list_inserter< assign_detail::call_push_back< BOOST_STD_EXTENSION_NAMESPACE::slist >, V > + operator+=( BOOST_STD_EXTENSION_NAMESPACE::slist& c, V2&& v ) + { + return push_back( c )( boost::forward(v) ); + } + +#endif } } diff --git a/include/boost/assign/std/stack.hpp b/include/boost/assign/std/stack.hpp index e528f16..5b0e07c 100644 --- a/include/boost/assign/std/stack.hpp +++ b/include/boost/assign/std/stack.hpp @@ -17,12 +17,14 @@ #include #include +#include #include namespace boost { namespace assign { +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class V, class C, class V2 > inline list_inserter< assign_detail::call_push< std::stack >, V > @@ -30,7 +32,17 @@ namespace assign { return push( c )( v ); } - + +#else + + template< class V, class C, class V2 > + inline list_inserter< assign_detail::call_push< std::stack >, V > + operator+=(std::stack& c, V2&& v) + { + return push(c)(boost::forward(v)); + } + +#endif } } diff --git a/include/boost/assign/std/vector.hpp b/include/boost/assign/std/vector.hpp index 8861de9..50f0350 100644 --- a/include/boost/assign/std/vector.hpp +++ b/include/boost/assign/std/vector.hpp @@ -17,12 +17,14 @@ #include #include +#include #include namespace boost { namespace assign { +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class V, class A, class V2 > inline list_inserter< assign_detail::call_push_back< std::vector >, V > @@ -30,7 +32,17 @@ namespace assign { return push_back( c )( v ); } - + +#else + + template< class V, class A, class V2 > + inline list_inserter< assign_detail::call_push_back< std::vector >, V > + operator+=( std::vector& c, V2&& v ) + { + return push_back( c )( std::forward(v) ); + } + +#endif } } From 359d01c653c3b54b43cc2a76065269f368b9deb1 Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 7 Sep 2014 16:35:07 +0200 Subject: [PATCH 02/10] updated comments --- include/boost/assign/list_inserter.hpp | 1 - include/boost/assign/list_of.hpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/assign/list_inserter.hpp b/include/boost/assign/list_inserter.hpp index 50dafb5..8c17c83 100644 --- a/include/boost/assign/list_inserter.hpp +++ b/include/boost/assign/list_inserter.hpp @@ -384,7 +384,6 @@ namespace assign void insert(single_arg_type, T&& t) { // Special implementation for single argument overload to prevent accidental casts (type-cast using functional notation) - // Use static_cast for single argument to prevent accidental casts (type-cast using functional notation) Argument a(boost::forward(t)); insert_(boost::move(a)); } diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index f32c65c..303ede3 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -86,7 +86,7 @@ namespace assign_detail ::boost::decay >::type Ty; public: - // boost::decay does not remove cv from class types + // boost::decay does not remove cv from types that don't decay to pointer typedef BOOST_DEDUCED_TYPENAME mpl::if_c< ::boost::is_pointer::value, Ty, From c3b2335ca27b8a12ae2415014bea187262bef14f Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 2 Nov 2014 12:02:33 +0100 Subject: [PATCH 03/10] fix ambiguities introduced with rvalue support --- include/boost/assign/list_inserter.hpp | 109 ++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/include/boost/assign/list_inserter.hpp b/include/boost/assign/list_inserter.hpp index 8c17c83..b97a86a 100644 --- a/include/boost/assign/list_inserter.hpp +++ b/include/boost/assign/list_inserter.hpp @@ -58,7 +58,18 @@ namespace assign_detail fun_repeater( std::size_t sz_, Fun r ) : sz( sz_ ), val( r ) { } }; - + + + template< class T > + struct is_repeater : boost::false_type {}; + + template< class T > + struct is_repeater< boost::assign_detail::repeater > : boost::true_type{}; + + template< class Fun > + struct is_repeater< boost::assign_detail::fun_repeater > : boost::true_type{}; + + template< class C > class call_push_back { @@ -198,8 +209,9 @@ namespace assign template< class Function, class Argument = assign_detail::forward_n_arguments > class list_inserter { - struct single_arg_type {}; - struct n_arg_type {}; + struct single_arg_type {}; + struct n_arg_type {}; + struct repeater_arg_type {}; typedef BOOST_DEDUCED_TYPENAME mpl::if_c< is_same::value, n_arg_type, @@ -231,14 +243,6 @@ namespace assign insert_( r ); return *this; } -#else - template< class T > - list_inserter& operator=( T&& r ) - { - insert_(boost::forward(r)); - return *this; - } -#endif template< class T > list_inserter& operator=( assign_detail::repeater r ) @@ -252,21 +256,12 @@ namespace assign return operator,( r ); } -#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > list_inserter& operator,( const T& r ) { insert_( r ); return *this; } -#else - template< class T > - list_inserter& operator,(T&& r) - { - insert_( boost::forward(r) ); - return *this; - } -#endif #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) template< class T > @@ -287,6 +282,38 @@ namespace assign { return repeat_fun( r.sz, r.val ); } +#else + // BOOST_NO_CXX11_RVALUE_REFERENCES + template< class T > + list_inserter& operator=(T&& r) + { + return operator,(boost::forward(r)); + } +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template< class T > + list_inserter& operator,(T&& r) + { + typedef BOOST_DEDUCED_TYPENAME mpl::if_c< assign_detail::is_repeater< T >::value, + repeater_arg_type, + arg_type >::type tag; + + insert(boost::forward(r), tag()); + return *this; + } +#else + // we add the tag as the first argument when using variadic templates + template< class T > + list_inserter& operator,(T&& r) + { + typedef BOOST_DEDUCED_TYPENAME mpl::if_c< assign_detail::is_repeater< T >::value, + repeater_arg_type, + arg_type >::type tag; + + insert(tag(), boost::forward(r)); + return *this; + } +#endif +#endif template< class T > list_inserter& repeat( std::size_t sz, T r ) @@ -384,8 +411,7 @@ namespace assign void insert(single_arg_type, T&& t) { // Special implementation for single argument overload to prevent accidental casts (type-cast using functional notation) - Argument a(boost::forward(t)); - insert_(boost::move(a)); + insert_(boost::forward(t)); } template< class T1, class T2, class... Ts > @@ -401,7 +427,44 @@ namespace assign } #endif - + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + template< class T > + void insert( T&& r, arg_type) + { + insert_( boost::forward(r) ); + } + + template< class T > + void insert(assign_detail::repeater r, repeater_arg_type) + { + repeat(r.sz, r.val); + } + + template< class Nullary_function > + void insert(const assign_detail::fun_repeater& r, repeater_arg_type) + { + repeat_fun(r.sz, r.val); + } +#else + template< class T > + void insert(repeater_arg_type, assign_detail::repeater r) + { + repeat(r.sz, r.val); + } + + template< class Nullary_function > + void insert(repeater_arg_type, const assign_detail::fun_repeater& r) + { + repeat_fun(r.sz, r.val); + } +#endif +#endif + + Function fun_private() const { return insert_; From 9582156680c74cb885c77e0db9d1174c251ead09 Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 2 Nov 2014 13:10:49 +0100 Subject: [PATCH 04/10] fix ambiguity in ptr_map_inserter --- include/boost/assign/ptr_map_inserter.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/assign/ptr_map_inserter.hpp b/include/boost/assign/ptr_map_inserter.hpp index 3445270..efe5d87 100644 --- a/include/boost/assign/ptr_map_inserter.hpp +++ b/include/boost/assign/ptr_map_inserter.hpp @@ -84,7 +84,7 @@ namespace assign ptr_map_inserter& operator()(Key&& k, Ts&&... ts) { key_type key(boost::forward(k)); - m_.insert(boost::move(key), new obj_type(boost::forward(ts)...)); + m_.insert(key, new obj_type(boost::forward(ts)...)); return *this; } From 6b2274e56ef10b3db059b4799dbfb876f432e58a Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 2 Nov 2014 13:13:54 +0100 Subject: [PATCH 05/10] added std::array support --- include/boost/assign/list_of.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index 303ede3..7bd945e 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -96,6 +96,10 @@ namespace assign_detail template< class T, std::size_t sz > type_traits::yes_type assign_is_array( const array* ); +#ifndef BOOST_NO_CXX11_HDR_ARRAY + template< class T, std::size_t sz > + type_traits::yes_type assign_is_array( const std::array* ); +#endif type_traits::no_type assign_is_array( ... ); template< class T, class U > type_traits::yes_type assign_is_pair( const std::pair* ); From a54f3a340b516c27d82ffc3e47a4cf07ba970039 Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 2 Nov 2014 13:32:44 +0100 Subject: [PATCH 06/10] added missing array include --- include/boost/assign/list_of.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index 7bd945e..b8a5e4a 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -32,6 +32,9 @@ #include #include #include +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include +#endif #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) From 81e595a1187acab8308edfc5999bb0158b8fc09a Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 2 Nov 2014 14:20:34 +0100 Subject: [PATCH 07/10] fix ambiguity with generic_list conversion operator --- include/boost/assign/list_of.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index b8a5e4a..f6b9492 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -491,12 +492,25 @@ namespace assign_detail { return range( boost::begin(r), boost::end(r) ); } +#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276 ) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) + template< class Container, class = decltype(Container(generic_list().begin(), generic_list().end())) > + operator Container() const + { + return this-> BOOST_NESTED_TEMPLATE convert_to_container(); + } + template< class Container, class = typename boost::enable_if< boost::is_same< boost::type_traits::yes_type, decltype(assign_is_array((Container*)0))> >::type, class=void> + operator Container() const + { + return this-> BOOST_NESTED_TEMPLATE convert_to_container(); + } +#else template< class Container > operator Container() const { return this-> BOOST_NESTED_TEMPLATE convert_to_container(); } +#endif }; ///////////////////////////////////////////////////////////////////////// From a86c4f4c9788119a4943d39b802b1bac32a502af Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 9 Nov 2014 12:10:26 +0100 Subject: [PATCH 08/10] fix ambiguity with static_generic_list conversion operator --- include/boost/assign/list_of.hpp | 154 ++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 65 deletions(-) diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index f6b9492..6a0e4a7 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -57,8 +57,8 @@ namespace boost #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) template< class T, std::size_t sz > class array; -#endif - +#endif + namespace assign_detail { ///////////////////////////////////////////////////////////////////////// @@ -97,7 +97,7 @@ namespace assign_detail BOOST_DEDUCED_TYPENAME ::boost::remove_cv::type>::type type; #endif }; - + template< class T, std::size_t sz > type_traits::yes_type assign_is_array( const array* ); #ifndef BOOST_NO_CXX11_HDR_ARRAY @@ -107,10 +107,10 @@ namespace assign_detail type_traits::no_type assign_is_array( ... ); template< class T, class U > type_traits::yes_type assign_is_pair( const std::pair* ); - type_traits::no_type assign_is_pair( ... ); + type_traits::no_type assign_is_pair( ... ); + - struct array_type_tag { #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) @@ -141,15 +141,15 @@ namespace assign_detail }; - + template< class DerivedTAssign, class Iterator > class converter { public: // Range operations typedef Iterator iterator; typedef Iterator const_iterator; - - iterator begin() const + + iterator begin() const { return static_cast(this)->begin(); } @@ -158,14 +158,14 @@ namespace assign_detail { return static_cast(this)->end(); } - + public: template< class Container > Container convert_to_container() const { static Container* c = 0; - BOOST_STATIC_CONSTANT( bool, is_array_flag = sizeof( assign_detail::assign_is_array( c ) ) + BOOST_STATIC_CONSTANT( bool, is_array_flag = sizeof( assign_detail::assign_is_array( c ) ) == sizeof( type_traits::yes_type ) ); typedef BOOST_DEDUCED_TYPENAME mpl::if_c< is_array_flag, @@ -174,9 +174,9 @@ namespace assign_detail return convert( c, tag_type() ); } - + private: - + template< class Container > Container convert( const Container*, default_type_tag ) const { @@ -184,7 +184,7 @@ namespace assign_detail #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) // old Dinkumware doesn't support iterator type as template Container result; - iterator it = begin(), + iterator it = begin(), e = end(); while( it != e ) { @@ -206,25 +206,25 @@ namespace assign_detail BOOST_DEDUCED_TYPENAME remove_const::type ar; #else Array ar; -#endif +#endif const std::size_t sz = ar.size(); if( sz < static_cast(this)->size() ) throw assign::assignment_exception( "array initialized with too many elements" ); - std::size_t n = 0; - iterator i = begin(), + std::size_t n = 0; + iterator i = begin(), e = end(); for( ; i != e; ++i, ++n ) ar[n] = *i; for( ; n < sz; ++n ) ar[n] = value_type(); - return ar; + return ar; } template< class Adapter > Adapter convert_to_adapter( const Adapter* = 0 ) const { Adapter a; - iterator i = begin(), + iterator i = begin(), e = end(); for( ; i != e; ++i ) a.push( *i ); @@ -241,7 +241,7 @@ namespace assign_detail adapter_converter( const converter& this_ ) : gl( this_ ) {} - adapter_converter( const adapter_converter& r ) + adapter_converter( const adapter_converter& r ) : gl( r.gl ) { } @@ -252,11 +252,11 @@ namespace assign_detail } }; - public: + public: template< class Container > Container to_container( Container& c ) const { - return convert( &c, default_type_tag() ); + return convert( &c, default_type_tag() ); } adapter_converter to_adapter() const @@ -267,7 +267,7 @@ namespace assign_detail template< class Adapter > Adapter to_adapter( Adapter& a ) const { - return this->convert_to_adapter( &a ); + return this->convert_to_adapter( &a ); } template< class Array > @@ -294,7 +294,7 @@ namespace assign_detail { return !( l == r ); } - + template< class T, class I, class Range > inline bool operator!=( const Range& l, const converter& r ) { @@ -336,7 +336,7 @@ namespace assign_detail { return !( l > r ); } - + template< class T, class I, class Range > inline bool operator>=( const converter& l, const Range& r ) { @@ -350,40 +350,40 @@ namespace assign_detail } template< class T, class I, class Elem, class Traits > - inline std::basic_ostream& + inline std::basic_ostream& operator<<( std::basic_ostream& Os, const converter& r ) { return Os << ::boost::make_iterator_range( r.begin(), r.end() ); } - + ///////////////////////////////////////////////////////////////////////// // Part 1: flexible, but inefficient interface - ///////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////// - template< class T > - class generic_list : + template< class T > + class generic_list : public converter< generic_list< BOOST_DEDUCED_TYPENAME assign_decay::type >, - BOOST_DEDUCED_TYPENAME std::deque::type>::iterator > { typedef BOOST_DEDUCED_TYPENAME assign_decay::type Ty; typedef std::deque impl_type; mutable impl_type values_; - + public: typedef BOOST_DEDUCED_TYPENAME impl_type::iterator iterator; typedef iterator const_iterator; typedef BOOST_DEDUCED_TYPENAME impl_type::value_type value_type; typedef BOOST_DEDUCED_TYPENAME impl_type::size_type size_type; typedef BOOST_DEDUCED_TYPENAME impl_type::difference_type difference_type; - + public: iterator begin() const { return values_.begin(); } iterator end() const { return values_.end(); } bool empty() const { return values_.empty(); } size_type size() const { return values_.size(); } - + private: #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) void push_back( value_type r ) { values_.push_back( r ); } @@ -394,7 +394,7 @@ namespace assign_detail public: generic_list& operator,( const Ty& u ) { - this->push_back( u ); + this->push_back( u ); return *this; } @@ -402,7 +402,7 @@ namespace assign_detail generic_list& operator,( Ty&& u ) { - this->push_back( boost::move(u) ); + this->push_back( boost::move(u) ); return *this; } #endif @@ -431,8 +431,8 @@ namespace assign_detail #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value #define BOOST_ASSIGN_MAX_PARAMS 5 -#endif -#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) +#endif +#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U) #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u) #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u) @@ -448,7 +448,7 @@ namespace assign_detail return *this; \ } \ /**/ - + #include BOOST_PP_LOCAL_ITERATE() #else @@ -459,7 +459,7 @@ namespace assign_detail return *this; } #endif - + template< class U > generic_list& repeat( std::size_t sz, U u ) { @@ -468,7 +468,7 @@ namespace assign_detail this->push_back( u ); return *this; } - + template< class Nullary_function > generic_list& repeat_fun( std::size_t sz, Nullary_function fun ) { @@ -479,27 +479,32 @@ namespace assign_detail } template< class SinglePassIterator > - generic_list& range( SinglePassIterator first, + generic_list& range( SinglePassIterator first, SinglePassIterator last ) { for( ; first != last; ++first ) this->push_back( *first ); return *this; } - + template< class SinglePassRange > generic_list& range( const SinglePassRange& r ) { return range( boost::begin(r), boost::end(r) ); } -#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276 ) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) - template< class Container, class = decltype(Container(generic_list().begin(), generic_list().end())) > +#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) + template< class Container, + class = decltype(Container(generic_list().begin(), generic_list().end())) + > operator Container() const { return this-> BOOST_NESTED_TEMPLATE convert_to_container(); } - template< class Container, class = typename boost::enable_if< boost::is_same< boost::type_traits::yes_type, decltype(assign_is_array((Container*)0))> >::type, class=void> + template< class Container, + class = typename boost::enable_if< boost::is_same< boost::type_traits::yes_type, decltype(assign_is_array((Container*)0))> >::type, + class = void + > operator Container() const { return this-> BOOST_NESTED_TEMPLATE convert_to_container(); @@ -512,7 +517,7 @@ namespace assign_detail } #endif }; - + ///////////////////////////////////////////////////////////////////////// // Part 2: efficient, but inconvenient interface ///////////////////////////////////////////////////////////////////////// @@ -545,14 +550,14 @@ namespace assign_detail { return *ref_; } - + private: T* ref_; }; template< class T > - inline bool operator<( const assign_reference& l, + inline bool operator<( const assign_reference& l, const assign_reference& r ) { return l.get_ref() < r.get_ref(); @@ -566,16 +571,16 @@ namespace assign_detail } template< class T > - inline void swap( assign_reference& l, + inline void swap( assign_reference& l, assign_reference& r ) { l.swap( r ); } - + template< class T, int N > - struct static_generic_list : + struct static_generic_list : public converter< static_generic_list, assign_reference* > { private: @@ -588,7 +593,7 @@ namespace assign_detail typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; - + static_generic_list( T& r ) : current_(1) { @@ -601,7 +606,7 @@ namespace assign_detail return *this; } - iterator begin() const + iterator begin() const { return &refs_[0]; } @@ -613,7 +618,7 @@ namespace assign_detail size_type size() const { - return static_cast( current_ ); + return static_cast( current_ ); } bool empty() const @@ -622,7 +627,7 @@ namespace assign_detail } template< class ForwardIterator > - static_generic_list& range( ForwardIterator first, + static_generic_list& range( ForwardIterator first, ForwardIterator last ) { for( ; first != last; ++first ) @@ -642,11 +647,30 @@ namespace assign_detail return range( boost::begin(r), boost::end(r) ); } +#if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) + template< class Container, + class = decltype(Container(static_generic_list(*((T*)0)).begin(), static_generic_list(*((T*)0)).end())) + > + operator Container() const + { + return this-> BOOST_NESTED_TEMPLATE convert_to_container(); + } + + template< class Container, + class = typename boost::enable_if< boost::is_same< boost::type_traits::yes_type, decltype(assign_is_array((Container*)0))> >::type, + class = void + > + operator Container() const + { + return this-> BOOST_NESTED_TEMPLATE convert_to_container(); + } +#else template< class Container > operator Container() const { return this-> BOOST_NESTED_TEMPLATE convert_to_container(); } +#endif private: void insert( T& r ) @@ -654,9 +678,9 @@ namespace assign_detail refs_[current_] = r; ++current_; } - + static_generic_list(); - + mutable assign_reference refs_[N]; int current_; }; @@ -675,7 +699,7 @@ namespace assign } #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class T > - inline assign_detail::generic_list + inline assign_detail::generic_list list_of( const T& t ) { return assign_detail::generic_list()( t ); @@ -698,7 +722,7 @@ namespace assign { return assign_detail::static_generic_list::type,N>( t ); } - + template< int N, class T > inline assign_detail::static_generic_list::type,N> cref_list_of( const T& t ) @@ -717,7 +741,7 @@ namespace assign return assign_detail::generic_list()(u, BOOST_ASSIGN_PARAMS3(n)); \ } \ /**/ - + #include BOOST_PP_LOCAL_ITERATE() #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) @@ -729,7 +753,7 @@ namespace assign return assign_detail::generic_list< tuple >()( tuple( u, BOOST_ASSIGN_PARAMS3(n) )); \ } \ /**/ - + #include BOOST_PP_LOCAL_ITERATE() #else @@ -757,8 +781,8 @@ namespace assign #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< class Key, class T > inline assign_detail::generic_list< std::pair - < - BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type, + < + BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type, BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type > > map_list_of( const Key& k, const T& t ) @@ -770,8 +794,8 @@ namespace assign template< class F, class S > inline assign_detail::generic_list< std::pair - < - BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type, + < + BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type, BOOST_DEDUCED_TYPENAME assign_detail::assign_decay::type > > pair_list_of( const F& f, const S& s ) From 66303f8beeee3a92b2480748dc9bace188fde4e1 Mon Sep 17 00:00:00 2001 From: VemundH Date: Sun, 9 Nov 2014 12:16:52 +0100 Subject: [PATCH 09/10] fix the most common ambiguity for systems with initializer_list support but no decltype N3276 --- include/boost/assign/list_of.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index 6a0e4a7..3a69f7c 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -36,6 +36,9 @@ #ifndef BOOST_NO_CXX11_HDR_ARRAY #include #endif +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#include +#endif #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) @@ -140,7 +143,13 @@ namespace assign_detail #endif }; +#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST + template< class C > + struct is_initializer_list : boost::false_type {}; + template< class E > + struct is_initializer_list< std::initializer_list > : boost::true_type {}; +#endif template< class DerivedTAssign, class Iterator > class converter @@ -509,6 +518,14 @@ namespace assign_detail { return this-> BOOST_NESTED_TEMPLATE convert_to_container(); } +#elif !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) + template< class Container, + class = typename boost::disable_if< is_initializer_list >::type + > + operator Container() const + { + return this-> BOOST_NESTED_TEMPLATE convert_to_container(); + } #else template< class Container > operator Container() const @@ -664,6 +681,14 @@ namespace assign_detail { return this-> BOOST_NESTED_TEMPLATE convert_to_container(); } +#elif !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) + template< class Container, + class = typename boost::disable_if< is_initializer_list >::type + > + operator Container() const + { + return this-> BOOST_NESTED_TEMPLATE convert_to_container(); + } #else template< class Container > operator Container() const From 7fc1b97cfe05613f5c8b72d04fe3f9d82aecbdb1 Mon Sep 17 00:00:00 2001 From: VemundH Date: Wed, 3 Dec 2014 19:34:19 +0100 Subject: [PATCH 10/10] use boost::declval --- include/boost/assign/list_of.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/assign/list_of.hpp b/include/boost/assign/list_of.hpp index 3a69f7c..360d231 100644 --- a/include/boost/assign/list_of.hpp +++ b/include/boost/assign/list_of.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -503,7 +504,7 @@ namespace assign_detail } #if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) template< class Container, - class = decltype(Container(generic_list().begin(), generic_list().end())) + class = decltype(Container(boost::declval >().begin(), boost::declval >().end())) > operator Container() const { @@ -666,7 +667,7 @@ namespace assign_detail #if !defined(BOOST_NO_CXX11_DECLTYPE_N3276) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) template< class Container, - class = decltype(Container(static_generic_list(*((T*)0)).begin(), static_generic_list(*((T*)0)).end())) + class = decltype(Container(boost::declval >().begin(), boost::declval >().end())) > operator Container() const {