diff options
| author | Eric Fiselier <eric@efcs.ca> | 2016-05-07 01:04:55 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2016-05-07 01:04:55 +0000 |
| commit | 15551efd432d797ce49c320ade8ab516d783491c (patch) | |
| tree | 5ca73490b77bf70ff23f61e369e7d3c9a8955b30 /libcxx/test/support | |
| parent | 7fa7dc36fed383098cd20f2bb94480e9562f17cf (diff) | |
| download | bcm5719-llvm-15551efd432d797ce49c320ade8ab516d783491c.tar.gz bcm5719-llvm-15551efd432d797ce49c320ade8ab516d783491c.zip | |
Add <experimental/memory_resource>
Reviewers: mclow.lists, EricWF
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D20007
llvm-svn: 268829
Diffstat (limited to 'libcxx/test/support')
| -rw-r--r-- | libcxx/test/support/test_memory_resource.hpp | 506 | ||||
| -rw-r--r-- | libcxx/test/support/type_id.h | 57 | ||||
| -rw-r--r-- | libcxx/test/support/uses_alloc_types.hpp | 298 |
3 files changed, 861 insertions, 0 deletions
diff --git a/libcxx/test/support/test_memory_resource.hpp b/libcxx/test/support/test_memory_resource.hpp new file mode 100644 index 00000000000..88fb41d55ec --- /dev/null +++ b/libcxx/test/support/test_memory_resource.hpp @@ -0,0 +1,506 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef SUPPORT_TEST_MEMORY_RESOURCE_HPP +#define SUPPORT_TEST_MEMORY_RESOURCE_HPP + +#include <experimental/memory_resource> +#include <memory> +#include <type_traits> +#include <cstddef> +#include <cstdlib> +#include <cstring> +#include <cassert> +#include "test_macros.h" + +struct AllocController; + // 'AllocController' is a concrete type that instruments and controls the + // behavior of of test allocators. + +template <class T> +class CountingAllocator; + // 'CountingAllocator' is an basic implementation of the 'Allocator' + // requirements that use the 'AllocController' interface. + +template <class T> +class MinAlignAllocator; + // 'MinAlignAllocator' is an instrumented test type which implements the + // 'Allocator' requirements. 'MinAlignAllocator' ensures that it *never* + // returns a pointer to over-aligned storage. For example + // 'MinAlignPointer<char>{}.allocate(...)' will never a 2-byte aligned + // pointer. + +template <class T> +class NullAllocator; + // 'NullAllocator' is an instrumented test type which implements the + // 'Allocator' requirements except that 'allocator' and 'deallocate' are + // nops. + + +#define DISALLOW_COPY(Type) \ + Type(Type const&) = delete; \ + Type& operator=(Type const&) = delete + +constexpr std::size_t MaxAlignV = alignof(std::max_align_t); + +struct TestException {}; + +struct AllocController { + int copy_constructed = 0; + int move_constructed = 0; + + int alive = 0; + int alloc_count = 0; + int dealloc_count = 0; + int is_equal_count = 0; + + std::size_t alive_size; + std::size_t allocated_size; + std::size_t deallocated_size; + + std::size_t last_size = 0; + std::size_t last_align = 0; + void * last_pointer = 0; + + std::size_t last_alloc_size = 0; + std::size_t last_alloc_align = 0; + void * last_alloc_pointer = nullptr; + + std::size_t last_dealloc_size = 0; + std::size_t last_dealloc_align = 0; + void * last_dealloc_pointer = nullptr; + + bool throw_on_alloc = false; + + AllocController() = default; + + void countAlloc(void* p, size_t s, size_t a) { + ++alive; + ++alloc_count; + alive_size += s; + allocated_size += s; + last_pointer = last_alloc_pointer = p; + last_size = last_alloc_size = s; + last_align = last_alloc_align = a; + } + + void countDealloc(void* p, size_t s, size_t a) { + --alive; + ++dealloc_count; + alive_size -= s; + deallocated_size += s; + last_pointer = last_dealloc_pointer = p; + last_size = last_dealloc_size = s; + last_align = last_dealloc_align = a; + } + + void reset() { std::memset(this, 0, sizeof(*this)); } + +public: + bool checkAlloc(void* p, size_t s, size_t a) const { + return p == last_alloc_pointer && + s == last_alloc_size && + a == last_alloc_align; + } + + bool checkAlloc(void* p, size_t s) const { + return p == last_alloc_pointer && + s == last_alloc_size; + } + + bool checkAllocAtLeast(void* p, size_t s, size_t a) const { + return p == last_alloc_pointer && + s <= last_alloc_size && + a <= last_alloc_align; + } + + bool checkAllocAtLeast(void* p, size_t s) const { + return p == last_alloc_pointer && + s <= last_alloc_size; + } + + bool checkDealloc(void* p, size_t s, size_t a) const { + return p == last_dealloc_pointer && + s == last_dealloc_size && + a == last_dealloc_align; + } + + bool checkDealloc(void* p, size_t s) const { + return p == last_dealloc_pointer && + s == last_dealloc_size; + } + + bool checkDeallocMatchesAlloc() const { + return last_dealloc_pointer == last_alloc_pointer && + last_dealloc_size == last_alloc_size && + last_dealloc_align == last_alloc_align; + } + + void countIsEqual() { + ++is_equal_count; + } + + bool checkIsEqualCalledEq(int n) const { + return is_equal_count == n; + } +private: + DISALLOW_COPY(AllocController); +}; + +template <class T> +class CountingAllocator +{ +public: + typedef T value_type; + typedef T* pointer; + CountingAllocator() = delete; + explicit CountingAllocator(AllocController& PP) : P(&PP) {} + + CountingAllocator(CountingAllocator const& other) : P(other.P) { + P->copy_constructed += 1; + } + + CountingAllocator(CountingAllocator&& other) : P(other.P) { + P->move_constructed += 1; + } + + template <class U> + CountingAllocator(CountingAllocator<U> const& other) TEST_NOEXCEPT : P(other.P) { + P->copy_constructed += 1; + } + + template <class U> + CountingAllocator(CountingAllocator<U>&& other) TEST_NOEXCEPT : P(other.P) { + P->move_constructed += 1; + } + + T* allocate(std::size_t n) + { + void* ret = ::operator new(n*sizeof(T)); + P->countAlloc(ret, n*sizeof(T), alignof(T)); + return static_cast<T*>(ret); + } + + void deallocate(T* p, std::size_t n) + { + void* vp = static_cast<void*>(p); + P->countDealloc(vp, n*sizeof(T), alignof(T)); + ::operator delete(vp); + } + + AllocController& getController() const { return *P; } + +private: + template <class Tp> friend class CountingAllocator; + AllocController *P; +}; + +template <class T, class U> +inline bool operator==(CountingAllocator<T> const& x, + CountingAllocator<U> const& y) { + return &x.getController() == &y.getController(); +} + +template <class T, class U> +inline bool operator!=(CountingAllocator<T> const& x, + CountingAllocator<U> const& y) { + return !(x == y); +} + +template <class T> +class MinAlignedAllocator +{ +public: + typedef T value_type; + typedef T* pointer; + + MinAlignedAllocator() = delete; + + explicit MinAlignedAllocator(AllocController& R) : P(&R) {} + + MinAlignedAllocator(MinAlignedAllocator const& other) : P(other.P) { + P->copy_constructed += 1; + } + + MinAlignedAllocator(MinAlignedAllocator&& other) : P(other.P) { + P->move_constructed += 1; + } + + template <class U> + MinAlignedAllocator(MinAlignedAllocator<U> const& other) TEST_NOEXCEPT : P(other.P) { + P->copy_constructed += 1; + } + + template <class U> + MinAlignedAllocator(MinAlignedAllocator<U>&& other) TEST_NOEXCEPT : P(other.P) { + P->move_constructed += 1; + } + + T* allocate(std::size_t n) { + char* aligned_ptr = (char*)::operator new(alloc_size(n*sizeof(T))); + assert(is_max_aligned(aligned_ptr)); + + char* unaligned_ptr = aligned_ptr + alignof(T); + assert(is_min_aligned(unaligned_ptr)); + + P->countAlloc(unaligned_ptr, n * sizeof(T), alignof(T)); + + return ((T*)unaligned_ptr); + } + + void deallocate(T* p, std::size_t n) { + assert(is_min_aligned(p)); + + char* aligned_ptr = ((char*)p) - alignof(T); + assert(is_max_aligned(aligned_ptr)); + + P->countDealloc(p, n*sizeof(T), alignof(T)); + + return ::operator delete(static_cast<void*>(aligned_ptr)); + } + + AllocController& getController() const { return *P; } + +private: + static const std::size_t BlockSize = alignof(std::max_align_t); + + static std::size_t alloc_size(std::size_t s) { + std::size_t bytes = (s + BlockSize - 1) & ~(BlockSize - 1); + bytes += BlockSize; + assert(bytes % BlockSize == 0); + return bytes / BlockSize; + } + + static bool is_max_aligned(void* p) { + return reinterpret_cast<std::size_t>(p) % BlockSize == 0; + } + + static bool is_min_aligned(void* p) { + if (alignof(T) == BlockSize) { + return is_max_aligned(p); + } else { + return reinterpret_cast<std::size_t>(p) % BlockSize == alignof(T); + } + } + + template <class Tp> friend class MinAlignedAllocator; + mutable AllocController *P; +}; + + +template <class T, class U> +inline bool operator==(MinAlignedAllocator<T> const& x, + MinAlignedAllocator<U> const& y) { + return &x.getController() == &y.getController(); +} + +template <class T, class U> +inline bool operator!=(MinAlignedAllocator<T> const& x, + MinAlignedAllocator<U> const& y) { + return !(x == y); +} + +template <class T> +class NullAllocator +{ +public: + typedef T value_type; + typedef T* pointer; + NullAllocator() = delete; + explicit NullAllocator(AllocController& PP) : P(&PP) {} + + NullAllocator(NullAllocator const& other) : P(other.P) { + P->copy_constructed += 1; + } + + NullAllocator(NullAllocator&& other) : P(other.P) { + P->move_constructed += 1; + } + + template <class U> + NullAllocator(NullAllocator<U> const& other) TEST_NOEXCEPT : P(other.P) { + P->copy_constructed += 1; + } + + template <class U> + NullAllocator(NullAllocator<U>&& other) TEST_NOEXCEPT : P(other.P) { + P->move_constructed += 1; + } + + T* allocate(std::size_t n) + { + P->countAlloc(nullptr, n*sizeof(T), alignof(T)); + return nullptr; + } + + void deallocate(T* p, std::size_t n) + { + void* vp = static_cast<void*>(p); + P->countDealloc(vp, n*sizeof(T), alignof(T)); + } + + AllocController& getController() const { return *P; } + +private: + template <class Tp> friend class NullAllocator; + AllocController *P; +}; + +template <class T, class U> +inline bool operator==(NullAllocator<T> const& x, + NullAllocator<U> const& y) { + return &x.getController() == &y.getController(); +} + +template <class T, class U> +inline bool operator!=(NullAllocator<T> const& x, + NullAllocator<U> const& y) { + return !(x == y); +} + + + +template <class ProviderT, int = 0> +class TestResourceImp : public std::experimental::pmr::memory_resource +{ +public: + static int resource_alive; + static int resource_constructed; + static int resource_destructed; + + static void resetStatics() { + assert(resource_alive == 0); + resource_alive = 0; + resource_constructed = 0; + resource_destructed = 0; + } + + using memory_resource = std::experimental::pmr::memory_resource; + using Provider = ProviderT; + + int value; + + explicit TestResourceImp(int val = 0) : value(val) { + ++resource_alive; + ++resource_constructed; + } + + ~TestResourceImp() noexcept { + --resource_alive; + ++resource_destructed; + } + + void reset() { C.reset(); P.reset(); } + AllocController& getController() { return C; } + + bool checkAlloc(void* p, std::size_t s, std::size_t a) const + { return C.checkAlloc(p, s, a); } + + bool checkDealloc(void* p, std::size_t s, std::size_t a) const + { return C.checkDealloc(p, s, a); } + + bool checkIsEqualCalledEq(int n) const { return C.checkIsEqualCalledEq(n); } + +protected: + virtual void * do_allocate(std::size_t s, std::size_t a) { + if (C.throw_on_alloc) { +#ifndef TEST_HAS_NO_EXCEPTIONS + throw TestException{}; +#else + assert(false); +#endif + } + void* ret = P.allocate(s, a); + C.countAlloc(ret, s, a); + return ret; + } + + virtual void do_deallocate(void * p, std::size_t s, std::size_t a) { + C.countDealloc(p, s, a); + P.deallocate(p, s, a); + } + + virtual bool do_is_equal(memory_resource const & other) const noexcept { + C.countIsEqual(); + TestResourceImp const * o = dynamic_cast<TestResourceImp const *>(&other); + return o && o->value == value; + } +private: + mutable AllocController C; + mutable Provider P; + DISALLOW_COPY(TestResourceImp); +}; + +template <class Provider, int N> +int TestResourceImp<Provider, N>::resource_alive = 0; + +template <class Provider, int N> +int TestResourceImp<Provider, N>::resource_constructed = 0; + +template <class Provider, int N> +int TestResourceImp<Provider, N>::resource_destructed = 0; + + +struct NullProvider { + NullProvider() {} + void* allocate(size_t, size_t) { return nullptr; } + void deallocate(void*, size_t, size_t) {} + void reset() {} +private: + DISALLOW_COPY(NullProvider); +}; + +struct NewDeleteProvider { + NewDeleteProvider() {} + void* allocate(size_t s, size_t) { return ::operator new(s); } + void deallocate(void* p, size_t, size_t) { ::operator delete(p); } + void reset() {} +private: + DISALLOW_COPY(NewDeleteProvider); +}; + +template <size_t Size = 4096 * 10> // 10 pages worth of memory. +struct BufferProvider { + char buffer[Size]; + void* next = &buffer; + size_t space = Size; + + BufferProvider() {} + + void* allocate(size_t s, size_t a) { + void* ret = std::align(s, a, next, space); + if (ret == nullptr) { +#ifndef TEST_HAS_NO_EXCEPTIONS + throw std::bad_alloc(); +#else + assert(false); +#endif + } + + return ret; + } + + void deallocate(void*, size_t, size_t) {} + + void reset() { + next = &buffer; + space = Size; + } +private: + DISALLOW_COPY(BufferProvider); +}; + +using NullResource = TestResourceImp<NullProvider, 0>; +using NewDeleteResource = TestResourceImp<NewDeleteProvider, 0>; +using TestResource = TestResourceImp<BufferProvider<>, 0>; +using TestResource1 = TestResourceImp<BufferProvider<>, 1>; +using TestResource2 = TestResourceImp<BufferProvider<>, 2>; + + +#endif /* SUPPORT_TEST_MEMORY_RESOURCE_HPP */ diff --git a/libcxx/test/support/type_id.h b/libcxx/test/support/type_id.h new file mode 100644 index 00000000000..309f0884e4a --- /dev/null +++ b/libcxx/test/support/type_id.h @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef SUPPORT_TYPE_ID_H +#define SUPPORT_TYPE_ID_H + +#include <functional> +#include <cassert> + +#include "test_macros.h" + +#if TEST_STD_VER < 11 +#error This header requires C++11 or greater +#endif + +// TypeID - Represent a unique identifier for a type. TypeID allows equality +// comparisons between different types. +struct TypeID { + friend bool operator==(TypeID const& LHS, TypeID const& RHS) + {return LHS.m_id == RHS.m_id; } + friend bool operator!=(TypeID const& LHS, TypeID const& RHS) + {return LHS.m_id != RHS.m_id; } +private: + explicit constexpr TypeID(const int* xid) : m_id(xid) {} + + TypeID(const TypeID&) = delete; + TypeID& operator=(TypeID const&) = delete; + + const int* const m_id; + template <class T> friend TypeID const& makeTypeID(); + +}; + +// makeTypeID - Return the TypeID for the specified type 'T'. +template <class T> +inline TypeID const& makeTypeID() { + static int dummy; + static const TypeID id(&dummy); + return id; +} + +template <class ...Args> +struct ArgumentListID {}; + +// makeArgumentID - Create and return a unique identifier for a given set +// of arguments. +template <class ...Args> +inline TypeID const& makeArgumentID() { + return makeTypeID<ArgumentListID<Args...>>(); +} + +#endif // SUPPORT_TYPE_ID_H diff --git a/libcxx/test/support/uses_alloc_types.hpp b/libcxx/test/support/uses_alloc_types.hpp new file mode 100644 index 00000000000..f68b842a708 --- /dev/null +++ b/libcxx/test/support/uses_alloc_types.hpp @@ -0,0 +1,298 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef USES_ALLOC_TYPES_HPP +#define USES_ALLOC_TYPES_HPP + +# include <experimental/memory_resource> +# include <experimental/utility> +# include <memory> +# include <cassert> + +#include "test_memory_resource.hpp" +#include "type_id.h" + +// There are two forms of uses-allocator construction: +// (1) UA_AllocArg: 'T(allocator_arg_t, Alloc const&, Args&&...)' +// (2) UA_AllocLast: 'T(Args&&..., Alloc const&)' +// 'UA_None' represents non-uses allocator construction. +enum class UsesAllocatorType { + UA_None = 0, + UA_AllocArg = 2, + UA_AllocLast = 4 +}; +constexpr UsesAllocatorType UA_None = UsesAllocatorType::UA_None; +constexpr UsesAllocatorType UA_AllocArg = UsesAllocatorType::UA_AllocArg; +constexpr UsesAllocatorType UA_AllocLast = UsesAllocatorType::UA_AllocLast; + +template <class Alloc, std::size_t N> +class UsesAllocatorV1; + // Implements form (1) of uses-allocator construction from the specified + // 'Alloc' type and exactly 'N' additional arguments. It also provides + // non-uses allocator construction from 'N' arguments. This test type + // blows up when form (2) of uses-allocator is even considered. + +template <class Alloc, std::size_t N> +class UsesAllocatorV2; + // Implements form (2) of uses-allocator construction from the specified + // 'Alloc' type and exactly 'N' additional arguments. It also provides + // non-uses allocator construction from 'N' arguments. + +template <class Alloc, std::size_t N> +class UsesAllocatorV3; + // Implements both form (1) and (2) of uses-allocator construction from + // the specified 'Alloc' type and exactly 'N' additional arguments. It also + // provides non-uses allocator construction from 'N' arguments. + +template <class Alloc, std::size_t> +class NotUsesAllocator; + // Implements both form (1) and (2) of uses-allocator construction from + // the specified 'Alloc' type and exactly 'N' additional arguments. It also + // provides non-uses allocator construction from 'N' arguments. However + // 'NotUsesAllocator' never provides a 'allocator_type' typedef so it is + // never automatically uses-allocator constructed. + + +template <class ...ArgTypes, class TestType> +bool checkConstruct(TestType& value, UsesAllocatorType form, + typename TestType::CtorAlloc const& alloc) + // Check that 'value' was constructed using the specified 'form' of + // construction and with the specified 'ArgTypes...'. Additionally + // check that 'value' was constructed using the specified 'alloc'. +{ + if (form == UA_None) { + return value.template checkConstruct<ArgTypes&&...>(form); + } else { + return value.template checkConstruct<ArgTypes&&...>(form, alloc); + } +} + + +template <class ...ArgTypes, class TestType> +bool checkConstruct(TestType& value, UsesAllocatorType form) { + return value.template checkConstruct<ArgTypes&&...>(form); +} + +template <class TestType> +bool checkConstructionEquiv(TestType& T, TestType& U) + // check that 'T' and 'U' where initialized in the exact same manner. +{ + return T.checkConstructEquiv(U); +} + +//////////////////////////////////////////////////////////////////////////////// +namespace detail { + +template <bool IsZero, size_t N, class ArgList, class ...Args> +struct TakeNImp; + +template <class ArgList, class ...Args> +struct TakeNImp<true, 0, ArgList, Args...> { + typedef ArgList type; +}; + +template <size_t N, class ...A1, class F, class ...R> +struct TakeNImp<false, N, ArgumentListID<A1...>, F, R...> + : TakeNImp<N-1 == 0, N - 1, ArgumentListID<A1..., F>, R...> {}; + +template <size_t N, class ...Args> +struct TakeNArgs : TakeNImp<N == 0, N, ArgumentListID<>, Args...> {}; + +template <class T> +struct Identity { typedef T type; }; + +template <class T> +using IdentityT = typename Identity<T>::type; + +template <bool Value> +using EnableIfB = typename std::enable_if<Value, bool>::type; + +} // end namespace detail + +using detail::EnableIfB; + +struct AllocLastTag {}; + +template <class Alloc> +struct UsesAllocatorTestBase { +public: + using CtorAlloc = typename std::conditional< + std::is_same<Alloc, std::experimental::erased_type>::value, + std::experimental::pmr::memory_resource*, + Alloc + >::type; + + template <class ...ArgTypes> + bool checkConstruct(UsesAllocatorType expectType) const { + return expectType == constructor_called && + makeArgumentID<ArgTypes...>() == *args_id; + } + + template <class ...ArgTypes> + bool checkConstruct(UsesAllocatorType expectType, + CtorAlloc const& expectAlloc) const { + return expectType == constructor_called && + makeArgumentID<ArgTypes...>() == *args_id && + expectAlloc == allocator; + } + + bool checkConstructEquiv(UsesAllocatorTestBase& O) const { + return constructor_called == O.constructor_called + && *args_id == *O.args_id + && allocator == O.allocator; + } + +protected: + explicit UsesAllocatorTestBase(const TypeID* aid) + : args_id(aid), constructor_called(UA_None), allocator() + {} + + template <class ...Args> + UsesAllocatorTestBase(std::allocator_arg_t, CtorAlloc const& a, Args&&...) + : args_id(&makeArgumentID<Args&&...>()), + constructor_called(UA_AllocArg), + allocator(a) + {} + + template <class ...Args> + UsesAllocatorTestBase(AllocLastTag, Args&&... args) + : args_id(nullptr), + constructor_called(UA_AllocLast) + { + typedef typename detail::TakeNArgs<sizeof...(Args) - 1, Args&&...>::type + ArgIDL; + args_id = &makeTypeID<ArgIDL>(); + getAllocatorFromPack(ArgIDL{}, std::forward<Args>(args)...); + } + +private: + template <class ...LArgs, class ...Args> + void getAllocatorFromPack(ArgumentListID<LArgs...>, Args&&... args) { + getAllocatorFromPackImp<LArgs const&...>(args...); + } + + template <class ...LArgs> + void getAllocatorFromPackImp(typename detail::Identity<LArgs>::type..., CtorAlloc const& alloc) { + allocator = alloc; + } + + const TypeID* args_id; + UsesAllocatorType constructor_called = UA_None; + CtorAlloc allocator; +}; + +template <class Alloc, size_t Arity> +class UsesAllocatorV1 : public UsesAllocatorTestBase<Alloc> +{ +public: + typedef Alloc allocator_type; + + using Base = UsesAllocatorTestBase<Alloc>; + using CtorAlloc = typename Base::CtorAlloc; + + UsesAllocatorV1() : Base(&makeArgumentID<>()) {} + + // Non-Uses Allocator Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity> = false> + UsesAllocatorV1(Args&&... args) : Base(&makeArgumentID<Args&&...>()) {}; + + // Uses Allocator Arg Ctor + template <class ...Args> + UsesAllocatorV1(std::allocator_arg_t tag, CtorAlloc const & a, Args&&... args) + : Base(tag, a, std::forward<Args>(args)...) + { } + + // BLOWS UP: Uses Allocator Last Ctor + template <class _First, class ...Args, EnableIfB<sizeof...(Args) == Arity> _Dummy = false> + constexpr UsesAllocatorV1(_First&& __first, Args&&... args) + { + static_assert(!std::is_same<_First, _First>::value, ""); + } +}; + + +template <class Alloc, size_t Arity> +class UsesAllocatorV2 : public UsesAllocatorTestBase<Alloc> +{ +public: + typedef Alloc allocator_type; + + using Base = UsesAllocatorTestBase<Alloc>; + using CtorAlloc = typename Base::CtorAlloc; + + UsesAllocatorV2() : Base(&makeArgumentID<>()) {} + + // Non-Uses Allocator Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity> = false> + UsesAllocatorV2(Args&&... args) : Base(&makeArgumentID<Args&&...>()) {}; + + // Uses Allocator Last Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity + 1> = false> + UsesAllocatorV2(Args&&... args) + : Base(AllocLastTag{}, std::forward<Args>(args)...) + {} +}; + +template <class Alloc, size_t Arity> +class UsesAllocatorV3 : public UsesAllocatorTestBase<Alloc> +{ +public: + typedef Alloc allocator_type; + + using Base = UsesAllocatorTestBase<Alloc>; + using CtorAlloc = typename Base::CtorAlloc; + + UsesAllocatorV3() : Base(&makeArgumentID<>()) {} + + // Non-Uses Allocator Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity> = false> + UsesAllocatorV3(Args&&... args) : Base(&makeArgumentID<Args&&...>()) {}; + + // Uses Allocator Arg Ctor + template <class ...Args> + UsesAllocatorV3(std::allocator_arg_t tag, CtorAlloc const& alloc, Args&&... args) + : Base(tag, alloc, std::forward<Args>(args)...) + {} + + // Uses Allocator Last Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity + 1> = false> + UsesAllocatorV3(Args&&... args) + : Base(AllocLastTag{}, std::forward<Args>(args)...) + {} +}; + +template <class Alloc, size_t Arity> +class NotUsesAllocator : public UsesAllocatorTestBase<Alloc> +{ +public: + // no allocator_type typedef provided + + using Base = UsesAllocatorTestBase<Alloc>; + using CtorAlloc = typename Base::CtorAlloc; + + NotUsesAllocator() : Base(&makeArgumentID<>()) {} + + // Non-Uses Allocator Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity> = false> + NotUsesAllocator(Args&&... args) : Base(&makeArgumentID<Args&&...>()) {}; + + // Uses Allocator Arg Ctor + template <class ...Args> + NotUsesAllocator(std::allocator_arg_t tag, CtorAlloc const& alloc, Args&&... args) + : Base(tag, alloc, std::forward<Args>(args)...) + {} + + // Uses Allocator Last Ctor + template <class ...Args, EnableIfB<sizeof...(Args) == Arity + 1> = false> + NotUsesAllocator(Args&&... args) + : Base(AllocLastTag{}, std::forward<Args>(args)...) + {} +}; + +#endif /* USES_ALLOC_TYPES_HPP */ |

