| 1 |
#include <string> |
| 2 |
#include <concepts> |
| 3 |
|
| 4 |
//convertible |
| 5 |
template <typename LHS, typename RHS> |
| 6 |
concept Convertible = |
| 7 |
requires(LHS lhs) |
| 8 |
{ |
| 9 |
{ lhs } -> std::convertible_to<RHS>; |
| 10 |
}; |
| 11 |
|
| 12 |
template <typename RHS, typename LHS> |
| 13 |
requires Convertible<LHS, RHS> |
| 14 |
void fun(LHS lhs) |
| 15 |
{} |
| 16 |
|
| 17 |
int main() |
| 18 |
{ // note: LHS is the <...>'s type |
| 19 |
fun<double>(12); // from int to double |
| 20 |
fun<int>(12.5); // from double to int |
| 21 |
fun<std::string>("a"); // from NTBS to string |
| 22 |
// fun<std::string>(12); // constraints not satisfied |
| 23 |
} |
| 24 |
//= |