yo/advancedtemplates/concepts/examples/constructible.cc
raw| 1 | #include <string> |
| 2 | #include <concepts> |
| 3 | |
| 4 | //constructible |
| 5 | template <typename LHS, typename ...Args> |
| 6 | concept Constructible = std::constructible_from<LHS, Args...>; |
| 7 | |
| 8 | template <typename T1, typename ...Args> |
| 9 | requires Constructible<T1, Args...> |
| 10 | T1 fun(Args &&...t2) |
| 11 | { |
| 12 | return T1( std::forward<Args>(t2)... ); |
| 13 | } |
| 14 | |
| 15 | int main() |
| 16 | { |
| 17 | std::string s{ fun<std::string>(5, 'a') }; |
| 18 | std::string s2{ fun<std::string>() }; // slightly weird... |
| 19 | } |
| 20 | //= |