Код: Выделить всё
#include
void f(std::integral auto &i) {}
void g(const std::integral auto &i) {}
void h(std::integral auto &&i) {}
int main() {
int one = 1;
f(one);
g(one);
h(one); // "[...] the expression 'is_integral_v [with _Tp = int&]' evaluated to 'false'"
}
Код: Выделить всё
integralЯ могу обойти это, заменив h, например, на (см. https://godbolt.org/z/fa9f7eeq6)
Код: Выделить всё
void h1(auto &&i) requires std::integral {}
Код: Выделить всё
template
void h2(T &&i) requires std::integral {}
Код: Выделить всё
template
concept Integral_without_cvref = std::integral;
void h3(Integral_without_cvref auto &&i) {}
Есть ли более идиоматический/краткий способ объявления ограничений на пересылку ссылочных аргументов?
Подробнее здесь: https://stackoverflow.com/questions/797 ... e-argument
Мобильная версия