|
4 | 4 | #include <functional>
|
5 | 5 | #include <type_traits>
|
6 | 6 |
|
| 7 | +/** |
| 8 | + * \brief The namespace containing some type helpers for fpgen. |
| 9 | + */ |
7 | 10 | namespace fpgen::type {
|
8 | 11 |
|
| 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 | + */ |
9 | 28 | template <typename TFun, typename TOut, typename... TIns>
|
10 | 29 | using is_function_to = typename std::enable_if<
|
11 | 30 | std::is_convertible<TFun, std::function<TOut(TIns...)>>::value>::type;
|
12 | 31 |
|
| 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 | + */ |
13 | 47 | template <typename TFun, typename... TIns>
|
14 | 48 | using is_predicate = is_function_to<TFun, bool, TIns...>;
|
15 | 49 |
|
| 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 | + */ |
16 | 60 | template <typename TFun, typename... TIns>
|
17 | 61 | using output_type = typename std::invoke_result<TFun, TIns...>::type;
|
18 | 62 |
|
| 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 | + */ |
19 | 71 | template <typename T>
|
20 | 72 | using is_generator_type =
|
21 | 73 | typename std::enable_if<std::is_copy_assignable<T>::value>::type;
|
|
0 commit comments