-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdaw_contract_test.cpp
More file actions
38 lines (33 loc) · 931 Bytes
/
daw_contract_test.cpp
File metadata and controls
38 lines (33 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) Darrell Wright
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/beached/header_libraries
//
#include "daw/daw_do_not_optimize.h"
#include <daw/daw_contract.h>
#include <daw/daw_ensure.h>
struct positive_integral {
positive_integral( ) = default;
template<typename T>
constexpr bool operator( )( T const & value ) const {
return value >= T{};
}
};
int main( ) {
using pos_int = daw::contract<int, positive_integral>;
static constexpr auto v0 = pos_int( 42 );
constexpr int const &v0cr = v0;
(void)v0cr;
#if defined( DAW_USE_EXCEPTIONS )
bool has_error = false;
try {
int x = -1;
daw::do_not_optimize( x );
auto v1 = pos_int{ x };
(void)v1;
} catch( daw::daw_contract_violation const & ) { has_error = true; }
daw_ensure( has_error );
#endif
}