-
Notifications
You must be signed in to change notification settings - Fork 1
/
readme.txt
46 lines (36 loc) · 1.12 KB
/
readme.txt
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
usage example:
in `your_library.h`:
#pragma once
#include "snct_constraints.hpp"
namespace your
{
using Divisor = snct::Constrained<double, snct::Not<0.0>, snct::Finite>;
double inverse(Divisor d);
}
in `your_library.cpp`:
#include "your_library.h"
namespace your
{
double inverse(Divisor d)
{
return 1/d; //no error handling - all possible values of d are valid for division.
}
}
in user `main.cpp`:
#include your_library.h
int main()
{
if constexpr(exceptions_enabled)
{
return inverse(0.25); //will throw snct::Constraint_Exception if 0.25 is not a valid Divisor
}
else
{
auto optional_divisor = your::Divisor::factory(0.25); // returns std::nullopt_t if 0.25 is
// not a valid your::Divisor
if(optional_divisor)
return inverse(*optional_divisor);
else
/*do your preferred non-exceptional error handling*/;
}
}