According to en.cppreference.com (from what I can gather):
std::is_convertibleis a trait class requiring typesFrom&Toto be such that a function with return typeTothat returns aFromvalue can compile.std::convertible_tois a concept requiring typesFrom&Toto be as explained above, AND such that an r-value reference of typeFromcan be converted withstatic_cast<To>.
The requirement imposed by std::is_convertible seems relatively straight-forward. Conversely, the r-value reference casting requirement of std::convertible_to seems oddly specific for such a generic concept that is shown in simple examples for C++20 features.
Being a novice in C++, I could not quite understand some terminology and parts of the supplementary descriptions provided in both webpages and I cannot imagine the exact difference between the requirements of either.
Some inter-related questions:
- What are the practical implications for types
From&Toof not only being constrained bystd::is_convertiblebut also by the strange r-value reference casting requirement? - What kind of candidate types for
From&Toare additionally rejected by the r-value reference casting requirement? - Why might a programmer want to use either of
std::is_convertibleorstd::convertible_to, instead of the other, as constraints for their function return types or parameter types (aside from just the convenience of concepts)?
A simpler explanation or an example would help. Thank you!