-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdaw_function_ref_test.cpp
More file actions
69 lines (57 loc) · 1.38 KB
/
daw_function_ref_test.cpp
File metadata and controls
69 lines (57 loc) · 1.38 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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_function_ref.h>
#include <daw/daw_consteval.h>
#include <daw/daw_ensure.h>
#include <cstdio>
#include <iostream>
#include <string>
constexpr int func( daw::function_ref<int( int, int, int )> f ) {
return f( 1, 2, 3 ) * f( 4, 5, 7 );
}
DAW_CPP26_CONSTEVAL void test1( ) {
constexpr auto l = []( int a, int b, int c ) {
return a * b * c;
};
auto const r = func( l );
daw_ensure( r == 840 );
auto const r2 = func( +l );
daw_ensure( r2 == 840 );
}
inline constexpr int add( int a, int b, int c ) {
return a + b + c;
}
DAW_CONSTEVAL void test2( ) {
constexpr auto const r = func( add );
daw_ensure( r == 96 );
}
constexpr void func2( daw::function_ref<void( double, double )> f ) {
f( 1.2, 3.4 );
}
DAW_CPP26_CONSTEVAL void test3( ) {
auto fn = []( int a, std::string, double ) -> int {
return a;
};
auto fnr = daw::function_ref<void( int, std::string, float )>( fn );
fnr( 3, "Hello", 2.2f );
}
void test4( ) {
auto fn = []( int a ) {
std::cout << a << '\n';
};
auto fnr = daw::function_ref<void( int )>( fn );
fnr( 1 );
fnr = +fn;
fnr( 2 );
}
int main( ) {
test1( );
test2( );
test3( );
test4( );
}