Skip to content

Commit cde8298

Browse files
committed
Format initializer_list
1 parent ec46f29 commit cde8298

File tree

1 file changed

+65
-77
lines changed

1 file changed

+65
-77
lines changed

libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp

Lines changed: 65 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,112 +6,100 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03, c++11, c++14
9+
// REQUIRES: std-at-least-c++17
1010
// <optional>
1111

1212
// template <class U, class... Args>
1313
// constexpr
1414
// explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
1515

16+
#include <cassert>
17+
#include <memory>
1618
#include <optional>
1719
#include <type_traits>
18-
#include <memory>
1920
#include <vector>
20-
#include <cassert>
2121

2222
#include "test_macros.h"
2323

24-
using std::optional;
25-
using std::in_place_t;
2624
using std::in_place;
25+
using std::in_place_t;
26+
using std::optional;
27+
28+
class X {
29+
int i_;
30+
int j_ = 0;
2731

28-
class X
29-
{
30-
int i_;
31-
int j_ = 0;
3232
public:
33-
X() : i_(0) {}
34-
X(int i) : i_(i) {}
35-
X(int i, int j) : i_(i), j_(j) {}
33+
X() : i_(0) {}
34+
X(int i) : i_(i) {}
35+
X(int i, int j) : i_(i), j_(j) {}
3636

37-
~X() {}
37+
~X() {}
3838

39-
friend bool operator==(const X& x, const X& y)
40-
{return x.i_ == y.i_ && x.j_ == y.j_;}
39+
friend bool operator==(const X& x, const X& y) { return x.i_ == y.i_ && x.j_ == y.j_; }
4140
};
4241

43-
class Y
44-
{
45-
int i_;
46-
int j_ = 0;
42+
class Y {
43+
int i_;
44+
int j_ = 0;
45+
4746
public:
48-
constexpr Y() : i_(0) {}
49-
constexpr Y(int i) : i_(i) {}
50-
constexpr Y(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
47+
constexpr Y() : i_(0) {}
48+
constexpr Y(int i) : i_(i) {}
49+
constexpr Y(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
5150

52-
friend constexpr bool operator==(const Y& x, const Y& y)
53-
{return x.i_ == y.i_ && x.j_ == y.j_;}
51+
friend constexpr bool operator==(const Y& x, const Y& y) { return x.i_ == y.i_ && x.j_ == y.j_; }
5452
};
5553

56-
class Z
57-
{
58-
int i_;
59-
int j_ = 0;
54+
class Z {
55+
int i_;
56+
int j_ = 0;
57+
6058
public:
61-
Z() : i_(0) {}
62-
Z(int i) : i_(i) {}
63-
Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
64-
{TEST_THROW(6);}
59+
Z() : i_(0) {}
60+
Z(int i) : i_(i) {}
61+
Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) { TEST_THROW(6); }
6562

66-
friend bool operator==(const Z& x, const Z& y)
67-
{return x.i_ == y.i_ && x.j_ == y.j_;}
63+
friend bool operator==(const Z& x, const Z& y) { return x.i_ == y.i_ && x.j_ == y.j_; }
6864
};
6965

70-
int main(int, char**)
71-
{
72-
{
73-
static_assert(!std::is_constructible<X, std::initializer_list<int>&>::value, "");
74-
static_assert(!std::is_constructible<optional<X>, std::initializer_list<int>&>::value, "");
75-
}
76-
{
77-
optional<std::vector<int>> opt(in_place, {3, 1});
78-
assert(static_cast<bool>(opt) == true);
79-
assert((*opt == std::vector<int>{3, 1}));
80-
assert(opt->size() == 2);
81-
}
82-
{
83-
optional<std::vector<int>> opt(in_place, {3, 1}, std::allocator<int>());
84-
assert(static_cast<bool>(opt) == true);
85-
assert((*opt == std::vector<int>{3, 1}));
86-
assert(opt->size() == 2);
87-
}
88-
{
89-
static_assert(std::is_constructible<optional<Y>, std::initializer_list<int>&>::value, "");
90-
constexpr optional<Y> opt(in_place, {3, 1});
91-
static_assert(static_cast<bool>(opt) == true, "");
92-
static_assert(*opt == Y{3, 1}, "");
93-
94-
struct test_constexpr_ctor
95-
: public optional<Y>
96-
{
97-
constexpr test_constexpr_ctor(in_place_t, std::initializer_list<int> i)
98-
: optional<Y>(in_place, i) {}
99-
};
100-
101-
}
66+
int main(int, char**) {
67+
{
68+
static_assert(!std::is_constructible<X, std::initializer_list<int>&>::value, "");
69+
static_assert(!std::is_constructible<optional<X>, std::initializer_list<int>&>::value, "");
70+
}
71+
{
72+
optional<std::vector<int>> opt(in_place, {3, 1});
73+
assert(static_cast<bool>(opt) == true);
74+
assert((*opt == std::vector<int>{3, 1}));
75+
assert(opt->size() == 2);
76+
}
77+
{
78+
optional<std::vector<int>> opt(in_place, {3, 1}, std::allocator<int>());
79+
assert(static_cast<bool>(opt) == true);
80+
assert((*opt == std::vector<int>{3, 1}));
81+
assert(opt->size() == 2);
82+
}
83+
{
84+
static_assert(std::is_constructible<optional<Y>, std::initializer_list<int>&>::value, "");
85+
constexpr optional<Y> opt(in_place, {3, 1});
86+
static_assert(static_cast<bool>(opt) == true, "");
87+
static_assert(*opt == Y{3, 1}, "");
88+
89+
struct test_constexpr_ctor : public optional<Y> {
90+
constexpr test_constexpr_ctor(in_place_t, std::initializer_list<int> i) : optional<Y>(in_place, i) {}
91+
};
92+
}
10293
#ifndef TEST_HAS_NO_EXCEPTIONS
103-
{
104-
static_assert(std::is_constructible<optional<Z>, std::initializer_list<int>&>::value, "");
105-
try
106-
{
107-
optional<Z> opt(in_place, {3, 1});
108-
assert(false);
109-
}
110-
catch (int i)
111-
{
112-
assert(i == 6);
113-
}
94+
{
95+
static_assert(std::is_constructible<optional<Z>, std::initializer_list<int>&>::value, "");
96+
try {
97+
optional<Z> opt(in_place, {3, 1});
98+
assert(false);
99+
} catch (int i) {
100+
assert(i == 6);
114101
}
102+
}
115103
#endif
116104

117105
return 0;

0 commit comments

Comments
 (0)