• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1+++
2title = "Constrained template macros"
3+++
4
5*Overridable*: All of the following macros are overridable, define before inclusion.
6
7*Header*: `<boost/outcome/config.hpp>`
8
9These macros expand into either the syntax for directly specifying constrained templates in C++ 20, or into a SFINAE based emulation for earlier C++ versions. Form of usage looks as follows:
10
11```c++
12BOOST_OUTCOME_TEMPLATE(class ErrorCondEnum)
13  BOOST_OUTCOME_TREQUIRES(
14    // If this is a valid expression
15    BOOST_OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))),
16    // If this predicate is true
17    BOOST_OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>)
18    // Any additional requirements follow here ...
19  )
20  constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = {});
21```
22
23Be aware that slightly different semantics occur for real C++ 20 constrained templates than for the SFINAE emulation.
24
25- <a name="template"></a>`BOOST_OUTCOME_TEMPLATE(template args ...)`
26
27    Begins a constrained template declaration.
28
29- <a name="trequires"></a>`BOOST_OUTCOME_TREQUIRES(requirements ...)`
30
31    Specifies the requirements for the constrained template to be available for selection by the compiler.
32
33- <a name="texpr"></a>`BOOST_OUTCOME_TEXPR(expression)`
34
35    A requirement that the given expression is valid.
36
37- <a name="tpred"></a>`BOOST_OUTCOME_TPRED(boolean)`
38
39    A requirement that the given constant time expression is true.
40