Skip to content

Commit bbaa690

Browse files
Fix allocators and fancy pointers in deque/abi.compile.pass.cpp
1 parent 1c1a4a9 commit bbaa690

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

libcxx/test/libcxx/containers/sequences/deque/abi.compile.pass.cpp

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <cstdint>
1212
#include <deque>
13+
#include <iterator>
14+
#include <type_traits>
1315

1416
#include "min_allocator.h"
1517
#include "test_allocator.h"
@@ -18,6 +20,73 @@
1820
template <class T>
1921
class small_pointer {
2022
std::uint16_t offset;
23+
24+
public:
25+
using value_type = typename std::remove_cv<T>::type;
26+
using difference_type = std::int16_t;
27+
using reference = T&;
28+
using pointer = T*;
29+
using iterator_category = std::random_access_iterator_tag;
30+
31+
template <class CT,
32+
typename std::enable_if<std::is_same<const T, CT>::value && !std::is_const<T>::value, int>::type = 0>
33+
operator small_pointer<CT>() const;
34+
template <
35+
class Void,
36+
typename std::enable_if<std::is_same<Void, void>::value && std::is_convertible<T*, void*>::value, int>::type = 0>
37+
operator small_pointer<Void>() const;
38+
template <
39+
class CVoid,
40+
typename std::enable_if<std::is_same<CVoid, const void>::value && std::is_convertible<T*, const void*>::value,
41+
int>::type = 0>
42+
operator small_pointer<CVoid>() const;
43+
44+
T& operator*() const;
45+
T* operator->() const;
46+
T& operator[](difference_type) const;
47+
48+
small_pointer& operator++();
49+
small_pointer operator++(int);
50+
small_pointer& operator--();
51+
small_pointer operator--(int);
52+
small_pointer& operator+=(difference_type);
53+
small_pointer& operator-=(difference_type);
54+
55+
friend small_pointer operator+(small_pointer, difference_type);
56+
friend small_pointer operator+(difference_type, small_pointer);
57+
friend small_pointer operator-(small_pointer, difference_type);
58+
friend difference_type operator-(small_pointer, small_pointer);
59+
60+
friend bool operator==(small_pointer, small_pointer);
61+
#if TEST_STD_VER < 20
62+
friend bool operator!=(small_pointer, small_pointer);
63+
#endif
64+
friend bool operator<(small_pointer, small_pointer);
65+
friend bool operator>=(small_pointer, small_pointer);
66+
friend bool operator>(small_pointer, small_pointer);
67+
friend bool operator>=(small_pointer, small_pointer);
68+
69+
small_pointer pointer_to(T&);
70+
};
71+
72+
template <>
73+
class small_pointer<const void> {
74+
std::uint16_t offset;
75+
76+
public:
77+
template <class CT, typename std::enable_if<std::is_convertible<CT*, const void*>::value, int>::type = 0>
78+
explicit operator small_pointer<CT>() const;
79+
};
80+
81+
template <>
82+
class small_pointer<void*> {
83+
std::uint16_t offset;
84+
85+
public:
86+
operator small_pointer<const void>() const;
87+
88+
template <class T, typename std::enable_if<std::is_convertible<T*, void*>::value, int>::type = 0>
89+
explicit operator small_pointer<T>() const;
2190
};
2291

2392
template <class T>
@@ -33,8 +102,8 @@ class small_iter_allocator {
33102
template <class U>
34103
small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}
35104

36-
T* allocate(std::size_t n);
37-
void deallocate(T* p, std::size_t);
105+
pointer allocate(std::size_t n);
106+
void deallocate(pointer p, std::size_t);
38107

39108
friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }
40109
friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }
@@ -53,8 +122,8 @@ class final_small_iter_allocator final {
53122
template <class U>
54123
final_small_iter_allocator(final_small_iter_allocator<U>) TEST_NOEXCEPT {}
55124

56-
T* allocate(std::size_t n);
57-
void deallocate(T* p, std::size_t);
125+
pointer allocate(std::size_t n);
126+
void deallocate(pointer p, std::size_t);
58127

59128
friend bool operator==(final_small_iter_allocator, final_small_iter_allocator) { return true; }
60129
friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; }

0 commit comments

Comments
 (0)