@@ -6,9 +6,18 @@ STDSHARP_TEST_NAMESPACES;
6
6
using namespace default_operator ;
7
7
8
8
template <typename T>
9
- void arithmetic_test ()
9
+ void arithmetic_test ([[maybe_unused]] T v = {} )
10
10
{
11
- [[maybe_unused]] T v{};
11
+ STATIC_REQUIRE (requires { v += 1 ; });
12
+ STATIC_REQUIRE (requires { v -= 1 ; });
13
+ STATIC_REQUIRE (requires { v *= 1 ; });
14
+ STATIC_REQUIRE (requires { v /= 1 ; });
15
+ STATIC_REQUIRE (requires { v %= 1 ; });
16
+ STATIC_REQUIRE (requires { v &= 1 ; });
17
+ STATIC_REQUIRE (requires { v |= 1 ; });
18
+ STATIC_REQUIRE (requires { v ^= 1 ; });
19
+ STATIC_REQUIRE (requires { v <<= 1 ; });
20
+ STATIC_REQUIRE (requires { v >>= 1 ; });
12
21
13
22
STATIC_REQUIRE (requires { v + 1 ; });
14
23
STATIC_REQUIRE (requires { v - 1 ; });
@@ -23,10 +32,8 @@ void arithmetic_test()
23
32
}
24
33
25
34
template <typename T>
26
- void commutative_arithmetic_test ()
35
+ void commutative_arithmetic_test ([[maybe_unused]] T v = {} )
27
36
{
28
- [[maybe_unused]] T v{};
29
-
30
37
STATIC_REQUIRE (requires { 1 + v; });
31
38
STATIC_REQUIRE (requires { 1 - v; });
32
39
STATIC_REQUIRE (requires { 1 * v; });
@@ -40,43 +47,34 @@ void commutative_arithmetic_test()
40
47
STATIC_REQUIRE (requires { +v; });
41
48
}
42
49
43
- SCENARIO ( " incrementable " , " [default operator] " )
50
+ struct increase_t : increase
44
51
{
45
- [[maybe_unused]] struct : increase
46
- {
47
- using increase::operator ++;
48
- using increase::operator --;
52
+ using increase::operator ++;
53
+ using increase::operator --;
49
54
50
- auto & operator ++() { return * this ; }
55
+ increase_t & operator ++();
51
56
52
- auto & operator --() { return * this ; }
53
- } v{ };
57
+ increase_t & operator --();
58
+ };
54
59
55
- STATIC_REQUIRE (requires { v++; });
56
- STATIC_REQUIRE (requires { v--; });
60
+ SCENARIO (" incrementable" , " [default operator]" )
61
+ {
62
+ STATIC_REQUIRE (requires (increase_t v) { v++; });
63
+ STATIC_REQUIRE (requires (increase_t v) { v--; });
57
64
}
58
65
59
66
struct arith : arithmetic
60
67
{
61
- auto & operator +=(int /* unused*/ ) { return *this ; }
62
-
63
- auto & operator -=(int /* unused*/ ) { return *this ; }
64
-
65
- auto & operator *=(int /* unused*/ ) { return *this ; }
66
-
67
- auto & operator /=(int /* unused*/ ) { return *this ; }
68
-
69
- auto & operator %=(int /* unused*/ ) { return *this ; }
70
-
71
- auto & operator &=(int /* unused*/ ) { return *this ; }
72
-
73
- auto & operator |=(int /* unused*/ ) { return *this ; }
74
-
75
- auto & operator ^=(int /* unused*/ ) { return *this ; }
76
-
77
- auto & operator <<=(int /* unused*/ ) { return *this ; }
78
-
79
- auto & operator >>=(int /* unused*/ ) { return *this ; }
68
+ arith& operator +=(int );
69
+ arith& operator -=(int );
70
+ arith& operator *=(int );
71
+ arith& operator /=(int );
72
+ arith& operator %=(int );
73
+ arith& operator &=(int );
74
+ arith& operator |=(int );
75
+ arith& operator ^=(int );
76
+ arith& operator <<=(int );
77
+ arith& operator >>=(int );
80
78
};
81
79
82
80
SCENARIO (" arithmetic" , " [default operator]" ) { arithmetic_test<arith>(); }
@@ -138,15 +136,15 @@ SCENARIO("arrow", "[default operator]")
138
136
139
137
// TODO: multidimensional subscript
140
138
#if __cpp_multidimensional_subscript >= 202110L
141
- SCENARIO ( " subscript " , " [default operator] " )
139
+ struct subscript_t : subscript
142
140
{
143
- [[maybe_unused]] struct : subscript
144
- {
145
- using subscript::operator [];
141
+ using subscript::operator [];
146
142
147
- [[nodiscard]] auto operator [](const int /* unused */ ) const { return * this ; }
148
- } v{ };
143
+ subscript_t operator [](int ) const ;
144
+ };
149
145
150
- STATIC_REQUIRE (requires { v[0 , 1 ]; });
146
+ SCENARIO (" subscript" , " [default operator]" )
147
+ {
148
+ STATIC_REQUIRE (requires (subscript_t v) { v[0 , 1 ]; });
151
149
}
152
150
#endif
0 commit comments