Good ol' tag dispatch works fine too: https://godbolt.org/z/x8hsEK48K
Nice. I'd not thought of that one.
std::remove_const to remove the const qualifier from a type, std::remove_reference to remove the ref qualifier from a type, std::decay_t to combine the two with a little extra.
Isn't std::remove_cvref_t the combination of the first 2? What is the difference between std::remove_cvref_t and std::decay_t?
Yes, std::remove_cvref_t combines the other two, in fact I believe it does so precisely (see the "Possible Implementation" on cppreference.com). The "...with a little extra" that I mention for std::decay_t in the article is that it does the same as std::remove_cvref_t plus some standardization of array and function types to pointer types (again, see the "Possible implementation" of it on cppreference.com). For my purposes it doesn't really matter which to use, and I mostly prefer std::decay_t for its brevity.
C++
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.