@@ -6,9 +6,18 @@ STDSHARP_TEST_NAMESPACES;
66using namespace default_operator ;
77
88template <typename T>
9- void arithmetic_test ()
9+ void arithmetic_test ([[maybe_unused]] T v = {} )
1010{
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 ; });
1221
1322 STATIC_REQUIRE (requires { v + 1 ; });
1423 STATIC_REQUIRE (requires { v - 1 ; });
@@ -23,10 +32,8 @@ void arithmetic_test()
2332}
2433
2534template <typename T>
26- void commutative_arithmetic_test ()
35+ void commutative_arithmetic_test ([[maybe_unused]] T v = {} )
2736{
28- [[maybe_unused]] T v{};
29-
3037 STATIC_REQUIRE (requires { 1 + v; });
3138 STATIC_REQUIRE (requires { 1 - v; });
3239 STATIC_REQUIRE (requires { 1 * v; });
@@ -40,43 +47,34 @@ void commutative_arithmetic_test()
4047 STATIC_REQUIRE (requires { +v; });
4148}
4249
43- SCENARIO ( " incrementable " , " [default operator] " )
50+ struct increase_t : increase
4451{
45- [[maybe_unused]] struct : increase
46- {
47- using increase::operator ++;
48- using increase::operator --;
52+ using increase::operator ++;
53+ using increase::operator --;
4954
50- auto & operator ++() { return * this ; }
55+ increase_t & operator ++();
5156
52- auto & operator --() { return * this ; }
53- } v{ };
57+ increase_t & operator --();
58+ };
5459
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--; });
5764}
5865
5966struct arith : arithmetic
6067{
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 );
8078};
8179
8280SCENARIO (" arithmetic" , " [default operator]" ) { arithmetic_test<arith>(); }
@@ -138,15 +136,15 @@ SCENARIO("arrow", "[default operator]")
138136
139137// TODO: multidimensional subscript
140138#if __cpp_multidimensional_subscript >= 202110L
141- SCENARIO ( " subscript " , " [default operator] " )
139+ struct subscript_t : subscript
142140{
143- [[maybe_unused]] struct : subscript
144- {
145- using subscript::operator [];
141+ using subscript::operator [];
146142
147- [[nodiscard]] auto operator [](const int /* unused */ ) const { return * this ; }
148- } v{ };
143+ subscript_t operator [](int ) const ;
144+ };
149145
150- STATIC_REQUIRE (requires { v[0 , 1 ]; });
146+ SCENARIO (" subscript" , " [default operator]" )
147+ {
148+ STATIC_REQUIRE (requires (subscript_t v) { v[0 , 1 ]; });
151149}
152150#endif
0 commit comments