나는 pass template function as template argument을 알고 있었기 때문에 비슷한 방식으로 변수 템플릿을 전달하기 위해 고심하고 있습니다. 이 컴파일하면람다를 통해 변수 템플릿을 함수로 전달할 수 있습니까?
#define PASS_VARIABLE_TEMPLATE(name) [dummy=nullptr](auto&&...args) \
{return name<decltype(args)...>;}
//testing
template <typename T>
bool value = std::is_fundamental<T>::value;
template <typename Hax>
void print_bool(Hax h)
{
std::cout << h(int{}) << std::endl; // no error, wrong output
//std::cout << h(int{}, float{}) << std::endl; // error, good
}
int main()
{
print_bool(PASS_VARIABLE_TEMPLATE(value)); //prints 0 instead of 1
}
, 왜 출력이 잘못 : 여기
내가 뭘하려 최소한의 예입니다?
참조가 충분합니까? – lorro
@lorro 오, 어리석은 나를, 부패를 잊어 버렸습니다! 그러나 다른 한편으로는 참조/포인터 검사를 파괴 할 것입니다 ...이 경우도 검사 할 수 있어야합니다 :'int b; int & ref = a; h (ref); // 타입은 int &'당신은 '#DEFINE의 PASS_VARIABLE_TEMPLATE (이름) [= 더미 nullptr] (자동 && 인수)와 예상되는 결과를 얻을 수 – xinaiz
\t { \t \t 반환 이름 <유형 이름 표준 : remove_reference :: 유형>; \t}' –