From 7c6e677a23eb76e02230881431cf773f9153a942 Mon Sep 17 00:00:00 2001 From: Brian Lach Date: Thu, 10 Jan 2019 01:29:24 +0100 Subject: [PATCH] dtoolbase: add std::initializer_list constructors for pvector, epvector, pdeque, plist, pset, pmultiset Closes #520 --- dtool/src/dtoolbase/epvector.h | 3 +++ dtool/src/dtoolbase/pdeque.h | 3 ++- dtool/src/dtoolbase/plist.h | 2 ++ dtool/src/dtoolbase/pset.h | 4 ++++ dtool/src/dtoolbase/pvector.h | 2 ++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dtool/src/dtoolbase/epvector.h b/dtool/src/dtoolbase/epvector.h index e743ea4060..f97c80cda3 100644 --- a/dtool/src/dtoolbase/epvector.h +++ b/dtool/src/dtoolbase/epvector.h @@ -20,6 +20,8 @@ #include +#include + /** * Unfortunately, on Windows, std::vector can't be used for classes with * explicitly alignment requirements, due to a minor mistake in the template @@ -46,6 +48,7 @@ public: epvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator()) { } epvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator()) { } epvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator()) { } + epvector(std::initializer_list init, TypeHandle type_handle = pvector_type_handle) : base_class(std::move(init), allocator()) { } }; #else // HAVE_EIGEN diff --git a/dtool/src/dtoolbase/pdeque.h b/dtool/src/dtoolbase/pdeque.h index e7e9f96c28..2b5e5793aa 100644 --- a/dtool/src/dtoolbase/pdeque.h +++ b/dtool/src/dtoolbase/pdeque.h @@ -18,7 +18,7 @@ #include "pallocator.h" #include "register_type.h" #include - +#include #if !defined(USE_STL_ALLOCATOR) || defined(CPPPARSER) // If we're not using custom allocators, just use the standard class @@ -40,6 +40,7 @@ public: pdeque(TypeHandle type_handle = pdeque_type_handle) : std::deque >(allocator(type_handle)) { } pdeque(size_type n, TypeHandle type_handle = pdeque_type_handle) : std::deque >(n, Type(), allocator(type_handle)) { } pdeque(size_type n, const Type &value, TypeHandle type_handle = pdeque_type_handle) : std::deque >(n, value, allocator(type_handle)) { } + pdeque(std::initializer_list init, TypeHandle type_handle = pdeque_type_handle) : std::deque >(std::move(init), allocator(type_handle)) { } }; #endif // USE_STL_ALLOCATOR diff --git a/dtool/src/dtoolbase/plist.h b/dtool/src/dtoolbase/plist.h index 12d29880f3..b9810342b5 100644 --- a/dtool/src/dtoolbase/plist.h +++ b/dtool/src/dtoolbase/plist.h @@ -18,6 +18,7 @@ #include "pallocator.h" #include "register_type.h" #include +#include #if !defined(USE_STL_ALLOCATOR) || defined(CPPPARSER) // If we're not using custom allocators, just use the standard class @@ -40,6 +41,7 @@ public: plist(TypeHandle type_handle = plist_type_handle) : base_class(allocator(type_handle)) { } plist(size_type n, TypeHandle type_handle = plist_type_handle) : base_class(n, Type(), allocator(type_handle)) { } plist(size_type n, const Type &value, TypeHandle type_handle = plist_type_handle) : base_class(n, value, allocator(type_handle)) { } + plist(std::initializer_list init, TypeHandle type_handle = plist_type_handle) : base_class(std::move(init), allocator(type_handle)) { } typedef typename base_class::iterator iterator; typedef typename base_class::const_iterator const_iterator; diff --git a/dtool/src/dtoolbase/pset.h b/dtool/src/dtoolbase/pset.h index ff54486dfe..feece41b5b 100644 --- a/dtool/src/dtoolbase/pset.h +++ b/dtool/src/dtoolbase/pset.h @@ -24,6 +24,8 @@ #include #endif +#include + #if !defined(USE_STL_ALLOCATOR) || defined(CPPPARSER) // If we're not using custom allocators, just use the standard class // definition. @@ -52,6 +54,7 @@ public: typedef std::set base_class; pset(TypeHandle type_handle = pset_type_handle) : base_class(Compare(), allocator(type_handle)) { } pset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : base_class(comp, type_handle) { } + pset(std::initializer_list init, TypeHandle type_handle = pset_type_handle) : base_class(std::move(init), allocator(type_handle)) { } #ifdef USE_TAU std::pair @@ -110,6 +113,7 @@ public: typedef pallocator_single allocator; pmultiset(TypeHandle type_handle = pset_type_handle) : std::multiset(Compare(), allocator(type_handle)) { } pmultiset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : std::multiset(comp, type_handle) { } + pmultiset(std::initializer_list init, TypeHandle type_handle = pset_type_handle) : std::multiset(std::move(init), allocator(type_handle)) { } }; #ifdef HAVE_STL_HASH diff --git a/dtool/src/dtoolbase/pvector.h b/dtool/src/dtoolbase/pvector.h index 4199506d13..be60897d21 100644 --- a/dtool/src/dtoolbase/pvector.h +++ b/dtool/src/dtoolbase/pvector.h @@ -15,6 +15,7 @@ #define PVECTOR_H #include +#include #include "dtoolbase.h" #include "pallocator.h" @@ -51,6 +52,7 @@ public: explicit pvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator(type_handle)) { } explicit pvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator(type_handle)) { } pvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator(type_handle)) { } + pvector(std::initializer_list init, TypeHandle type_handle = pvector_type_handle) : base_class(std::move(init), allocator(type_handle)) { } pvector &operator =(const pvector ©) { base_class::operator =(copy);