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
|
||||
}
|
||||
Reference in New Issue
Block a user