私は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リターン名 ::タイプ>; \t} ' –