Skip to content

Commit 32d1a8e

Browse files
committed
fix constexpr.test.cpp
1 parent 329a2f2 commit 32d1a8e

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

tests/beman/inplace_vector/constexpr.test.cpp

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ static_assert(!has_constexpr_support<inplace_vector<std::unique_ptr<int>, 50>>);
4949
}), \
5050
"##NAME");
5151

52+
template <typename IV>
53+
constexpr IV vec_of(std::initializer_list<typename IV::value_type> &&il) {
54+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
55+
return IV(il);
56+
#else
57+
IV res;
58+
for (auto &ele : il) {
59+
res.unchecked_push_back(ele);
60+
}
61+
return res;
62+
#endif
63+
}
64+
5265
template <typename IV> constexpr void test_constructors() {
5366
using T = IV::value_type;
5467

@@ -71,36 +84,40 @@ template <typename IV> constexpr void test_constructors() {
7184
{
7285
IV v(beman::from_range_t{}, arr);
7386
}
87+
{
88+
IV v({0, 1});
89+
}
7490
#endif
7591
{
76-
IV other{0, 1};
92+
auto other = vec_of<IV>({0, 1});
7793
IV copy(other);
7894
}
7995
{
80-
IV other{0, 1};
96+
auto other = vec_of<IV>({0, 1});
8197
IV copy(std::move(other));
8298
}
83-
{
84-
IV v({0, 1});
85-
}
8699
}
87100
TEST(test_constructors);
88101

89102
template <typename IV> constexpr void test_op_eq() {
90103
using T = IV::value_type;
91104

92105
{
93-
IV v, other{0, 1};
106+
IV v;
107+
auto other = vec_of<IV>({0, 1});
94108
v = other;
95109
}
96110
{
97-
IV v, other{0, 1};
111+
IV v;
112+
auto other = vec_of<IV>({0, 1});
98113
v = std::move(other);
99114
}
115+
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
100116
{
101117
IV v;
102118
v = {0, 1};
103119
}
120+
#endif
104121
}
105122
TEST(test_op_eq);
106123

@@ -132,25 +149,19 @@ template <typename IV> constexpr void test_assignment() {
132149
TEST(test_assignment);
133150

134151
template <typename IV> constexpr void test_iterator_access() {
135-
using T = IV::value_type;
136-
137-
{
138-
IV v{0, 1};
139-
(void)v.begin();
140-
(void)v.end();
141-
(void)v.rbegin();
142-
(void)v.rend();
143-
(void)v.cbegin();
144-
(void)v.cend();
145-
(void)v.crbegin();
146-
(void)v.crend();
147-
}
152+
auto v = vec_of<IV>({0, 1});
153+
(void)v.begin();
154+
(void)v.end();
155+
(void)v.rbegin();
156+
(void)v.rend();
157+
(void)v.cbegin();
158+
(void)v.cend();
159+
(void)v.crbegin();
160+
(void)v.crend();
148161
}
149162
TEST(test_iterator_access);
150163

151164
template <typename IV> constexpr void test_size_capacity() {
152-
using T = IV::value_type;
153-
154165
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
155166
{
156167
IV v{0, 1};
@@ -177,7 +188,7 @@ TEST(test_size_capacity);
177188

178189
template <typename IV> constexpr void test_element_access() {
179190
{
180-
IV v{0, 1};
191+
auto v = vec_of<IV>({0, 1});
181192
(void)v[0];
182193
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
183194
(void)v.at(0);
@@ -187,7 +198,7 @@ template <typename IV> constexpr void test_element_access() {
187198
}
188199

189200
{
190-
const IV v{0, 1};
201+
auto v = vec_of<IV>({0, 1});
191202
(void)v[0];
192203
#if !BEMAN_INPLACE_VECTOR_FREESTANDING_DELETED()
193204
(void)v.at(0);
@@ -200,11 +211,11 @@ TEST(test_element_access);
200211

201212
template <typename IV> constexpr void test_data_access() {
202213
{
203-
IV v{0, 1};
214+
auto v = vec_of<IV>({0, 1});
204215
v.data();
205216
}
206217
{
207-
const IV v{0, 1};
218+
auto v = vec_of<IV>({0, 1});
208219
v.data();
209220
}
210221
}
@@ -258,19 +269,21 @@ template <typename IV> constexpr void test_modifiers() {
258269
#endif
259270

260271
{
261-
IV v, other{0, 1};
272+
IV v;
273+
auto other = vec_of<IV>({0, 1});
262274
v.swap(other);
263275
}
264276

265277
{
266-
IV v{0, 1};
278+
auto v = vec_of<IV>({0, 1});
267279
v.clear();
268280
}
269281
}
270282
TEST(test_modifiers);
271283

272284
template <typename IV> constexpr void test_op_comp() {
273-
IV v{0, 1, 2}, other{3, 4};
285+
auto v = vec_of<IV>({0, 1, 2});
286+
auto other = vec_of<IV>({3, 4});
274287

275288
(void)(v == v);
276289
(void)(v == other);
@@ -280,7 +293,7 @@ template <typename IV> constexpr void test_op_comp() {
280293
TEST(test_op_comp);
281294

282295
template <typename IV> constexpr void test_erase() {
283-
IV v{0, 1, 2, 3, 3, 5};
296+
auto v = vec_of<IV>({0, 1, 2, 3, 3, 5});
284297
(void)beman::erase(v, 3);
285298
(void)beman::erase_if(v, [](auto v) { return v < 3; });
286299
}

0 commit comments

Comments
 (0)