Код: Выделить всё
#include
#include
#include
template
requires (!std::is_scalar_v)
auto foo(T&&){
std::puts("pass by universal reference");
}
template
requires std::is_scalar_v
auto foo(T){
std::puts("pass by value");
}
int main(){
foo(42); // pass by value
foo(std::string{"hello"}); // pass by universal reference
return 0;
}
Код: Выделить всё
#include
#include
#include
template
using MaybeRef = std::conditional_t;
#include
template
struct Foo {
Foo(MaybeRef... args) {
static_assert(std::is_same_v);
static_assert(std::is_same_v);
std::puts("passed");
}
};
template
Foo(Ts&&...) -> Foo;
int main(){
std::string str = "hello";
Foo{42, str};
return 0;
}
Возможно ли это вообще и как?
Подробнее здесь: https://stackoverflow.com/questions/791 ... eclaration
Мобильная версия