Skip to content

Commit 4e4c2d0

Browse files
authored
Merge pull request #530 from beached/v2
Update function attributes and replace assert with daw_ensure
2 parents 2139551 + df0b59d commit 4e4c2d0

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

include/daw/daw_visit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace daw {
9393
}
9494

9595
template<typename Variant, std::enable_if_t<not has_variant_npos<Variant>, std::nullptr_t> = nullptr>
96-
DAW_CONSTEVAL bool is_empty( Variant const & ) {
96+
DAW_ATTRIB_INLINE constexpr bool is_empty( Variant const & ) {
9797
return false;
9898
}
9999

tests/daw_visit_test.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "daw/daw_visit.h"
1010

1111
#include "daw/daw_benchmark.h"
12+
#include "daw/daw_ensure.h"
1213

13-
#include <cassert>
1414
#include <exception>
1515
#include <optional>
1616
#include <variant>
@@ -242,24 +242,34 @@ int foofoo( std::variant<T0,
242242
} );
243243
}
244244

245+
bool visit_test_001( ) {
246+
auto v = std::variant<int, double>{ 5 };
247+
daw::do_not_optimize( v );
248+
auto r = daw::visit( v, []( auto a ) {
249+
return static_cast<int>( a );
250+
} );
251+
return r == 5;
252+
}
253+
245254
int main( ) {
246255
visit_nt_004( );
247256
visit_nt_005( );
248-
assert( foofoo( foobar( 0 ) ) == 0 );
249-
assert( foofoo( foobar( 1 ) ) == 1 );
250-
assert( foofoo( foobar( 2 ) ) == 2 );
251-
assert( foofoo( foobar( 3 ) ) == 3 );
252-
assert( foofoo( foobar( 4 ) ) == 4 );
253-
assert( foofoo( foobar( 5 ) ) == 5 );
254-
assert( foofoo( foobar( 6 ) ) == 6 );
255-
assert( foofoo( foobar( 7 ) ) == 7 );
256-
assert( foofoo( foobar( 8 ) ) == 8 );
257-
assert( foofoo( foobar( 9 ) ) == 9 );
258-
assert( foofoo( foobar( 10 ) ) == 10 );
259-
assert( foofoo( foobar( 11 ) ) == 11 );
260-
assert( foofoo( foobar( 12 ) ) == 12 );
261-
assert( foofoo( foobar( 13 ) ) == 13 );
262-
assert( foofoo( foobar( 14 ) ) == 14 );
263-
assert( foofoo( foobar( 15 ) ) == 15 );
264-
assert( foofoo( foobar( 16 ) ) == 16 );
257+
daw_ensure( visit_test_001( ) );
258+
daw_ensure( foofoo( foobar( 0 ) ) == 0 );
259+
daw_ensure( foofoo( foobar( 1 ) ) == 1 );
260+
daw_ensure( foofoo( foobar( 2 ) ) == 2 );
261+
daw_ensure( foofoo( foobar( 3 ) ) == 3 );
262+
daw_ensure( foofoo( foobar( 4 ) ) == 4 );
263+
daw_ensure( foofoo( foobar( 5 ) ) == 5 );
264+
daw_ensure( foofoo( foobar( 6 ) ) == 6 );
265+
daw_ensure( foofoo( foobar( 7 ) ) == 7 );
266+
daw_ensure( foofoo( foobar( 8 ) ) == 8 );
267+
daw_ensure( foofoo( foobar( 9 ) ) == 9 );
268+
daw_ensure( foofoo( foobar( 10 ) ) == 10 );
269+
daw_ensure( foofoo( foobar( 11 ) ) == 11 );
270+
daw_ensure( foofoo( foobar( 12 ) ) == 12 );
271+
daw_ensure( foofoo( foobar( 13 ) ) == 13 );
272+
daw_ensure( foofoo( foobar( 14 ) ) == 14 );
273+
daw_ensure( foofoo( foobar( 15 ) ) == 15 );
274+
daw_ensure( foofoo( foobar( 16 ) ) == 16 );
265275
}

0 commit comments

Comments
 (0)