]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/unordered/test/unordered/minimal_allocator.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / unordered / test / unordered / minimal_allocator.cpp
CommitLineData
7c673cae
FG
1
2// Copyright 2011 Daniel James.
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
b32b8144 6#include "../objects/test.hpp"
7c673cae 7#include <boost/detail/lightweight_test.hpp>
7c673cae 8#include <boost/static_assert.hpp>
b32b8144
FG
9#include <boost/type_traits/is_same.hpp>
10#include <boost/unordered/detail/implementation.hpp>
7c673cae 11
b32b8144
FG
12template <class Tp> struct SimpleAllocator
13{
14 typedef Tp value_type;
7c673cae 15
b32b8144 16 SimpleAllocator() {}
7c673cae 17
b32b8144 18 template <class T> SimpleAllocator(const SimpleAllocator<T>&) {}
7c673cae 19
b32b8144
FG
20 Tp* allocate(std::size_t n)
21 {
22 return static_cast<Tp*>(::operator new(n * sizeof(Tp)));
23 }
7c673cae 24
b32b8144 25 void deallocate(Tp* p, std::size_t) { ::operator delete((void*)p); }
7c673cae
FG
26};
27
b32b8144 28template <typename T> void test_simple_allocator()
7c673cae 29{
b32b8144 30 test::check_instances check_;
7c673cae 31
b32b8144
FG
32 typedef boost::unordered::detail::allocator_traits<SimpleAllocator<T> >
33 traits;
7c673cae 34
b32b8144
FG
35 BOOST_STATIC_ASSERT((boost::is_same<typename traits::allocator_type,
36 SimpleAllocator<T> >::value));
7c673cae 37
b32b8144 38 BOOST_STATIC_ASSERT((boost::is_same<typename traits::value_type, T>::value));
7c673cae 39
b32b8144
FG
40 BOOST_STATIC_ASSERT((boost::is_same<typename traits::pointer, T*>::value));
41 BOOST_STATIC_ASSERT(
42 (boost::is_same<typename traits::const_pointer, T const*>::value));
43 // BOOST_STATIC_ASSERT((boost::is_same<typename traits::void_pointer, void*
44 // >::value));
45 // BOOST_STATIC_ASSERT((boost::is_same<typename traits::const_void_pointer,
46 // void const*>::value));
7c673cae 47
b32b8144
FG
48 BOOST_STATIC_ASSERT(
49 (boost::is_same<typename traits::difference_type, std::ptrdiff_t>::value));
7c673cae
FG
50
51#if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1
b32b8144
FG
52 BOOST_STATIC_ASSERT((boost::is_same<typename traits::size_type,
53 std::make_unsigned<std::ptrdiff_t>::type>::value));
7c673cae 54#else
b32b8144
FG
55 BOOST_STATIC_ASSERT(
56 (boost::is_same<typename traits::size_type, std::size_t>::value));
7c673cae
FG
57#endif
58
b32b8144
FG
59 BOOST_TEST(!traits::propagate_on_container_copy_assignment::value);
60 BOOST_TEST(!traits::propagate_on_container_move_assignment::value);
61 BOOST_TEST(!traits::propagate_on_container_swap::value);
62
63 // rebind_alloc
64 // rebind_traits
7c673cae 65
b32b8144 66 SimpleAllocator<T> a;
7c673cae 67
b32b8144
FG
68 T* ptr1 = traits::allocate(a, 1);
69 // T* ptr2 = traits::allocate(a, 1, static_cast<void const*>(ptr1));
7c673cae 70
b32b8144
FG
71 traits::construct(a, ptr1, T(10));
72 // traits::construct(a, ptr2, T(30), ptr1);
7c673cae 73
b32b8144
FG
74 BOOST_TEST(*ptr1 == T(10));
75 // BOOST_TEST(*ptr2 == T(30));
7c673cae 76
b32b8144
FG
77 traits::destroy(a, ptr1);
78 // traits::destroy(a, ptr2);
7c673cae 79
b32b8144
FG
80 // traits::deallocate(a, ptr2, 1);
81 traits::deallocate(a, ptr1, 1);
7c673cae 82
b32b8144 83 traits::max_size(a);
7c673cae
FG
84}
85
86int main()
87{
b32b8144
FG
88 test_simple_allocator<int>();
89 test_simple_allocator<test::object>();
7c673cae 90
b32b8144 91 return boost::report_errors();
7c673cae 92}