aboutsummaryrefslogtreecommitdiff
path: root/EASTL/test/source/ConceptImpls.h
blob: e6c20ef8e1acba2f74bf76175938601fe46bb340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////

#ifndef CONCEPTSIMPLS_H
#define CONCEPTSIMPLS_H

#include <EASTL/type_traits.h>

#if !defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS) && !defined(EA_COMPILER_NO_DELETED_FUNCTIONS)

#define EASTL_TEST_CONCEPT_IMPLS

// This header provides a variety of helper classes that have interfaces corresponding to the concepts used to specify
// requirements of many STL containers and algorithms. These helper classes are used in tests to verify that containers
// and algorithms do not impose stricter requirements than specified by the standard on their arguments.

// Destructible - only valid operation on this class is to destroy it.

class Destructible
{
public:
	~Destructible() = default;

	Destructible() = delete;
	Destructible(const Destructible&) = delete;
	Destructible(Destructible&&) = delete;
	Destructible& operator=(const Destructible&) = delete;
	Destructible& operator=(Destructible&&) = delete;
};

// Unfortunately not all compilers handle type_traits reliably correctly currently so we can't straightforwardly
// static_assert everything that should be true of this class
static_assert(eastl::is_destructible<Destructible>::value, "eastl::is_destructible<Destructible>::value");
// static_assert(!eastl::is_default_constructible<Destructible>::value,
// "!eastl::is_default_constructible<Destructible>::value");
// static_assert(!is_copy_constructible<Destructible>::value, "!eastl::is_copy_constructible<Destructible>::value");
static_assert(!eastl::is_copy_assignable<Destructible>::value, "!eastl::is_copy_assignable<Destructible>::value");
// static_assert(!eastl::is_move_constructible<Destructible>::value,
// "!eastl::is_move_constructible<Destructible>::value");
static_assert(!eastl::is_move_assignable<Destructible>::value, "!eastl::is_move_assignable<Destructible>::value");

class DefaultConstructible
{
public:
	static const int defaultValue = 42;

	DefaultConstructible() : value(defaultValue) {}
	~DefaultConstructible() = default;

	DefaultConstructible(const DefaultConstructible&) = delete;
	DefaultConstructible(DefaultConstructible&&) = delete;
	DefaultConstructible& operator=(const DefaultConstructible&) = delete;
	DefaultConstructible& operator=(DefaultConstructible&&) = delete;

	const int value;
};


struct NotDefaultConstructible
{
	NotDefaultConstructible() = delete;
};
static_assert(!eastl::is_default_constructible<NotDefaultConstructible>::value, "'NotDefaultConstructible' is default constructible.");


class CopyConstructible
{
public:
	static const int defaultValue = 42;
	static CopyConstructible Create()
	{
		CopyConstructible x;
		return x;
	}

	CopyConstructible(const CopyConstructible&) = default;
	~CopyConstructible() = default;

	CopyConstructible& operator=(const CopyConstructible&) = delete;
	CopyConstructible& operator=(CopyConstructible&&) = delete;

	const int value;

private:
	CopyConstructible() : value(defaultValue) {}
};

// Unfortunately not all compilers handle type_traits reliably correctly currently so we can't straightforwardly
// static_assert everything that should be true of this class
static_assert(eastl::is_destructible<CopyConstructible>::value, "eastl::is_destructible<CopyConstructible>::value");
// static_assert(!eastl::is_default_constructible<CopyConstructible>::value,
// "!eastl::is_default_constructible<CopyConstructible>::value");
// static_assert(is_copy_constructible<CopyConstructible>::value, "is_copy_constructible<CopyConstructible>::value");
static_assert(eastl::is_copy_constructible<CopyConstructible>::value,
			  "eastl::is_copy_constructible<CopyConstructible>::value");
static_assert(!eastl::is_copy_assignable<CopyConstructible>::value,
			  "!eastl::is_copy_assignable<CopyConstructible>::value");
// static_assert(!eastl::is_move_constructible<CopyConstructible>::value,
// "!eastl::is_move_constructible<CopyConstructible>::value");
static_assert(!eastl::is_move_assignable<CopyConstructible>::value,
			  "!eastl::is_move_assignable<CopyConstructible>::value");

class MoveConstructible
{
public:
	static const int defaultValue = 42;
	static MoveConstructible Create()
	{
		return MoveConstructible{};
	}

	MoveConstructible(MoveConstructible&& x) : value(x.value) {}
	~MoveConstructible() = default;

	MoveConstructible(const MoveConstructible&) = delete;
	MoveConstructible& operator=(const MoveConstructible&) = delete;
	MoveConstructible& operator=(MoveConstructible&&) = delete;

	const int value;

private:
	MoveConstructible() : value(defaultValue) {}
};

class MoveAssignable
{
public:
	static const int defaultValue = 42;
	static MoveAssignable Create()
	{
		return MoveAssignable{};
	}

	MoveAssignable(MoveAssignable&& x) : value(x.value) {}
	MoveAssignable& operator=(MoveAssignable&& x)
	{
		value = x.value;
		return *this;
	}
	~MoveAssignable() = default;

	MoveAssignable(const MoveAssignable&) = delete;
	MoveAssignable& operator=(const MoveAssignable&) = delete;

	int value;

private:
	MoveAssignable() : value(defaultValue) {}
};

struct MoveAndDefaultConstructible
{
	static const int defaultValue = 42;

	MoveAndDefaultConstructible() : value(defaultValue) {}
	MoveAndDefaultConstructible(MoveAndDefaultConstructible&& x) : value(x.value) {}
	~MoveAndDefaultConstructible() = default;

	MoveAndDefaultConstructible(const MoveAndDefaultConstructible&) = delete;
	MoveAndDefaultConstructible& operator=(const MoveAndDefaultConstructible&) = delete;
	MoveAndDefaultConstructible& operator=(MoveAndDefaultConstructible&&) = delete;

	const int value;
};

struct MissingMoveConstructor
{
	MissingMoveConstructor() {}
	MissingMoveConstructor(const MissingMoveConstructor&) {}
	MissingMoveConstructor& operator=(MissingMoveConstructor&&) { return *this; }
	MissingMoveConstructor& operator=(const MissingMoveConstructor&) { return *this; }
	bool operator<(const MissingMoveConstructor&) const { return true; }
};

struct MissingMoveAssignable
{
	MissingMoveAssignable() {}
	MissingMoveAssignable(const MissingMoveAssignable&) {}
	MissingMoveAssignable(MissingMoveAssignable&&) {}
	MissingMoveAssignable& operator=(const MissingMoveAssignable&) { return *this; }
	bool operator<(const MissingMoveAssignable&) const { return true; }
};

struct MissingEquality
{
	MissingEquality& operator==(const MissingEquality&) = delete;
};

#endif  // !defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS) && !defined(EA_COMPILER_NO_DELETED_FUNCTIONS)

#endif  // CONCEPTSIMPLS_H