Skip to content

Commit 3e87a74

Browse files
committed
Documentation for the type traits
1 parent 284fc00 commit 3e87a74

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

inc/type_traits.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,70 @@
44
#include <functional>
55
#include <type_traits>
66

7+
/**
8+
* \brief The namespace containing some type helpers for fpgen.
9+
*/
710
namespace fpgen::type {
811

12+
/**
13+
* \brief Type trait deducing whether a type is a function from the input types
14+
* to the output type.
15+
*
16+
* In short, the function type `TFun` should have the signature `(TIns...) ->
17+
* TOut`. This can include any "free" function (plain C function pointer), any
18+
* lambda function, or any struct/class type supporting `TOut
19+
* operator()(TIns...)`. This is implemented using the type traits
20+
* `std::enable_if` and `std::is_convertible`. Usage: use as an extra template
21+
* type, like so:
22+
* `typename _ = fpgen::type::is_function_to<TFun, TOut, TIns...>`.
23+
*
24+
* \tparam TFun The function type.
25+
* \tparam TOut The output type for the function.
26+
* \tparam TIns The input type(s) for the function.
27+
*/
928
template <typename TFun, typename TOut, typename... TIns>
1029
using is_function_to = typename std::enable_if<
1130
std::is_convertible<TFun, std::function<TOut(TIns...)>>::value>::type;
1231

32+
/**
33+
* \brief Type trait deducing whether a type is a predicate.
34+
*
35+
* In short, the function type `TFun` should have the signature `(TIns...) ->
36+
* bool`. This can include any "free" function (plain C function pointer), any
37+
* lambda function, or any struct/class type supporting `bool
38+
* operator()(TIns...)`. This is implemented using fpgen::type::is_function_to.
39+
* Usage: use as an extra template type, like so:
40+
* `typename _ = fpgen::type::is_predicate<TFun, TIns...>`;
41+
* this is synonymous to using
42+
* `typename _ = fpgen::type::is_function_to<TFun, bool, TIns...>`.
43+
*
44+
* \tparam TFun The predicate function type.
45+
* \tparam TIns The input type(s) for the function.
46+
*/
1347
template <typename TFun, typename... TIns>
1448
using is_predicate = is_function_to<TFun, bool, TIns...>;
1549

50+
/**
51+
* \brief Type trait deducing the output type of a functional type.
52+
*
53+
* If the type `TFun` is a function type `(TIns...) -> TOut`, this type trait
54+
* will return `TOut`. Thie type trait is implemented using
55+
* `std::invoke_result`.
56+
*
57+
* \tparam TFun The function type.
58+
* \tparam TIns The input type(s) for the function.
59+
*/
1660
template <typename TFun, typename... TIns>
1761
using output_type = typename std::invoke_result<TFun, TIns...>::type;
1862

63+
/**
64+
* \brief Type trait deducing whether a type is fit as data type for a
65+
* generator.
66+
*
67+
* The type `T` will pass the test if it's copy-assignable.
68+
*
69+
* \tparam T The type to check.
70+
*/
1971
template <typename T>
2072
using is_generator_type =
2173
typename std::enable_if<std::is_copy_assignable<T>::value>::type;

0 commit comments

Comments
 (0)