Код: Выделить всё
template
concept ConvertibleWithoutNarrowing = requires (From&& from) {
{ std::type_identity_t{std::forward(from)}} -> std::same_as;
};
Код: Выделить всё
template
requires ConvertsWithoutNarrowing
void add(C& collection, const T& val) {…}
// Usage:
std::vector vec_i;
add(vec_i, 1); // OK
add(vec_i, 1.3); // Does not compile.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -narrowing
Мобильная версия