Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// static pointer allocate(allocator_type& a, size_type n);
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
value_type* allocate(std::size_t n)
|
||||
{
|
||||
assert(n == 10);
|
||||
return (value_type*)0xDEADBEEF;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
A<int> a;
|
||||
assert(std::allocator_traits<A<int> >::allocate(a, 10) == (int*)0xDEADBEEF);
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
value_type* allocate(std::size_t n)
|
||||
{
|
||||
assert(n == 10);
|
||||
return (value_type*)0xDEADBEEF;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
value_type* allocate(std::size_t n)
|
||||
{
|
||||
assert(n == 12);
|
||||
return (value_type*)0xEEADBEEF;
|
||||
}
|
||||
value_type* allocate(std::size_t n, const void* p)
|
||||
{
|
||||
assert(n == 11);
|
||||
assert(p == 0);
|
||||
return (value_type*)0xFEADBEEF;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
A<int> a;
|
||||
assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF);
|
||||
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
B<int> b;
|
||||
assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF);
|
||||
}
|
@@ -0,0 +1,143 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// template <class Ptr, class... Args>
|
||||
// static void construct(allocator_type& a, Ptr p, Args&&... args);
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
};
|
||||
|
||||
int b_construct = 0;
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
||||
template <class U, class ...Args>
|
||||
void construct(U* p, Args&& ...args)
|
||||
{
|
||||
++b_construct;
|
||||
::new ((void*)p) U(std::forward<Args>(args)...);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_VARIADICS
|
||||
};
|
||||
|
||||
struct A0
|
||||
{
|
||||
static int count;
|
||||
A0() {++count;}
|
||||
};
|
||||
|
||||
int A0::count = 0;
|
||||
|
||||
struct A1
|
||||
{
|
||||
static int count;
|
||||
A1(char c)
|
||||
{
|
||||
assert(c == 'c');
|
||||
++count;
|
||||
}
|
||||
};
|
||||
|
||||
int A1::count = 0;
|
||||
|
||||
struct A2
|
||||
{
|
||||
static int count;
|
||||
A2(char c, int i)
|
||||
{
|
||||
assert(c == 'd');
|
||||
assert(i == 5);
|
||||
++count;
|
||||
}
|
||||
};
|
||||
|
||||
int A2::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A0::count = 0;
|
||||
A<int> a;
|
||||
std::aligned_storage<sizeof(A0)>::type a0;
|
||||
assert(A0::count == 0);
|
||||
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
|
||||
assert(A0::count == 1);
|
||||
}
|
||||
{
|
||||
A1::count = 0;
|
||||
A<int> a;
|
||||
std::aligned_storage<sizeof(A1)>::type a1;
|
||||
assert(A1::count == 0);
|
||||
std::allocator_traits<A<int> >::construct(a, (A1*)&a1, 'c');
|
||||
assert(A1::count == 1);
|
||||
}
|
||||
{
|
||||
A2::count = 0;
|
||||
A<int> a;
|
||||
std::aligned_storage<sizeof(A2)>::type a2;
|
||||
assert(A2::count == 0);
|
||||
std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5);
|
||||
assert(A2::count == 1);
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
||||
{
|
||||
A0::count = 0;
|
||||
b_construct = 0;
|
||||
B<int> b;
|
||||
std::aligned_storage<sizeof(A0)>::type a0;
|
||||
assert(A0::count == 0);
|
||||
assert(b_construct == 0);
|
||||
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
|
||||
assert(A0::count == 1);
|
||||
assert(b_construct == 1);
|
||||
}
|
||||
{
|
||||
A1::count = 0;
|
||||
b_construct = 0;
|
||||
B<int> b;
|
||||
std::aligned_storage<sizeof(A1)>::type a1;
|
||||
assert(A1::count == 0);
|
||||
assert(b_construct == 0);
|
||||
std::allocator_traits<B<int> >::construct(b, (A1*)&a1, 'c');
|
||||
assert(A1::count == 1);
|
||||
assert(b_construct == 1);
|
||||
}
|
||||
{
|
||||
A2::count = 0;
|
||||
b_construct = 0;
|
||||
B<int> b;
|
||||
std::aligned_storage<sizeof(A2)>::type a2;
|
||||
assert(A2::count == 0);
|
||||
assert(b_construct == 0);
|
||||
std::allocator_traits<B<int> >::construct(b, (A2*)&a2, 'd', 5);
|
||||
assert(A2::count == 1);
|
||||
assert(b_construct == 1);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_VARIADICS
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// static void deallocate(allocator_type& a, pointer p, size_type n);
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int called = 0;
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
void deallocate(value_type* p, std::size_t n)
|
||||
{
|
||||
assert(p == (value_type*)0xDEADBEEF);
|
||||
assert(n == 10);
|
||||
++called;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
A<int> a;
|
||||
std::allocator_traits<A<int> >::deallocate(a, (int*)0xDEADBEEF, 10);
|
||||
assert(called == 1);
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// template <class Ptr>
|
||||
// static void destroy(allocator_type& a, Ptr p);
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
};
|
||||
|
||||
int b_destroy = 0;
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class U>
|
||||
void destroy(U* p)
|
||||
{
|
||||
++b_destroy;
|
||||
p->~U();
|
||||
}
|
||||
};
|
||||
|
||||
struct A0
|
||||
{
|
||||
static int count;
|
||||
~A0() {++count;}
|
||||
};
|
||||
|
||||
int A0::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A0::count = 0;
|
||||
A<int> a;
|
||||
std::aligned_storage<sizeof(A0)>::type a0;
|
||||
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
|
||||
assert(A0::count == 0);
|
||||
std::allocator_traits<A<int> >::destroy(a, (A0*)&a0);
|
||||
assert(A0::count == 1);
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
{
|
||||
A0::count = 0;
|
||||
b_destroy = 0;
|
||||
B<int> b;
|
||||
std::aligned_storage<sizeof(A0)>::type a0;
|
||||
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
|
||||
assert(A0::count == 0);
|
||||
assert(b_destroy == 0);
|
||||
std::allocator_traits<B<int> >::destroy(b, (A0*)&a0);
|
||||
assert(A0::count == 1);
|
||||
assert(b_destroy == 1);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// static size_type max_size(const allocator_type& a) noexcept;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
size_t max_size() const
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
{
|
||||
A<int> a;
|
||||
assert(std::allocator_traits<A<int> >::max_size(a) ==
|
||||
std::numeric_limits<std::size_t>::max());
|
||||
}
|
||||
{
|
||||
const A<int> a = {};
|
||||
assert(std::allocator_traits<A<int> >::max_size(a) ==
|
||||
std::numeric_limits<std::size_t>::max());
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
{
|
||||
B<int> b;
|
||||
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
|
||||
}
|
||||
{
|
||||
const B<int> b = {};
|
||||
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
|
||||
}
|
||||
#if __cplusplus >= 201103
|
||||
{
|
||||
std::allocator<int> a;
|
||||
static_assert(noexcept(std::allocator_traits<std::allocator<int>>::max_size(a)) == true, "");
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// static allocator_type
|
||||
// select_on_container_copy_construction(const allocator_type& a);
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
int id;
|
||||
explicit A(int i = 0) : id(i) {}
|
||||
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
int id;
|
||||
explicit B(int i = 0) : id(i) {}
|
||||
|
||||
B select_on_container_copy_construction() const
|
||||
{
|
||||
return B(100);
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A<int> a;
|
||||
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
|
||||
}
|
||||
{
|
||||
const A<int> a(0);
|
||||
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
|
||||
}
|
||||
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
{
|
||||
B<int> b;
|
||||
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
|
||||
}
|
||||
{
|
||||
const B<int> b(0);
|
||||
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
|
||||
}
|
||||
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::const_pointer
|
||||
// | pointer_traits<pointer>::rebind<const value_type>
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct Ptr {};
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Ptr<T> pointer;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct CPtr {};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef CPtr<T> pointer;
|
||||
typedef CPtr<const T> const_pointer;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), "");
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::const_void_pointer
|
||||
// | pointer_traits<pointer>::rebind<const void>
|
||||
// const_void_pointer;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct Ptr {};
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Ptr<T> pointer;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct CPtr {};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef CPtr<const void> const_void_pointer;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::const_void_pointer, Ptr<const void> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::const_void_pointer, const void*>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::const_void_pointer, CPtr<const void> >::value), "");
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::difference_type
|
||||
// | pointer_traits<pointer>::difference_type difference_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef short difference_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
struct pointer {};
|
||||
struct const_pointer {};
|
||||
struct void_pointer {};
|
||||
struct const_void_pointer {};
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
struct pointer_traits<C<char>::pointer>
|
||||
{
|
||||
typedef signed char difference_type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::difference_type, signed char>::value), "");
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::pointer | value_type* pointer;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct Ptr {};
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Ptr<T> pointer;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::pointer, Ptr<char> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::pointer, char*>::value), "");
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::propagate_on_container_copy_assignment
|
||||
// | false_type propagate_on_container_copy_assignment;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef std::true_type propagate_on_container_copy_assignment;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_copy_assignment, std::true_type>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_copy_assignment, std::false_type>::value), "");
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::propagate_on_container_move_assignment
|
||||
// | false_type propagate_on_container_move_assignment;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef std::true_type propagate_on_container_move_assignment;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_move_assignment, std::true_type>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_move_assignment, std::false_type>::value), "");
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::propagate_on_container_swap
|
||||
// | false_type propagate_on_container_swap;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef std::true_type propagate_on_container_swap;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_swap, std::true_type>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_swap, std::false_type>::value), "");
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct ReboundA {};
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class U> struct rebind {typedef ReboundA<U> other;};
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct ReboundB {};
|
||||
|
||||
template <class T, class U>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class V> struct rebind {typedef ReboundB<V, U> other;};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct D
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct E
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class U> struct rebind {typedef ReboundA<U> otter;};
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
|
||||
#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
|
||||
#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::size_type | size_t size_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef unsigned short size_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
struct pointer {};
|
||||
struct const_pointer {};
|
||||
struct void_pointer {};
|
||||
struct const_void_pointer {};
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
struct pointer_traits<C<char>::pointer>
|
||||
{
|
||||
typedef signed char difference_type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::size_type,
|
||||
std::make_unsigned<std::ptrdiff_t>::type>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::size_type,
|
||||
unsigned char>::value), "");
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc::void_pointer
|
||||
// | pointer_traits<pointer>::rebind<void>
|
||||
// void_pointer;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct Ptr {};
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Ptr<T> pointer;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct CPtr {};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef CPtr<void> void_pointer;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), "");
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef Alloc allocator_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::allocator_type, A<char> >::value), "");
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct ReboundA {};
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class U> struct rebind {typedef ReboundA<U> other;};
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct ReboundB {};
|
||||
|
||||
template <class T, class U>
|
||||
struct B
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class V> struct rebind {typedef ReboundB<V, U> other;};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct C
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct D
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct E
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
template <class U> struct rebind {typedef ReboundA<U> otter;};
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), "");
|
||||
#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), "");
|
||||
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), "");
|
||||
#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Alloc>
|
||||
// struct allocator_traits
|
||||
// {
|
||||
// typedef typename Alloc::value_type value_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_same<std::allocator_traits<A<char> >::value_type, char>::value), "");
|
||||
}
|
Reference in New Issue
Block a user