高階メタ関数

C++テンプレートテクニック 4-6


ここは自分なりのサンプルが全然思いつかなかった。とりあえずまったく意味のないシンプルなコードだけ書いてみた。

#include <iostream>
using std::cout; using std::endl;

template<class T>
struct bar {
    static const bool value = T::value;
};

template<int I,int J>
struct foo {
    static const bool value = I == J;
};

int main () {
    cout << bar< foo<1,1> >::value << endl;
}

この例の場合、そもそも

    cout << foo<1,1>::value << endl;

と書けばいいだけなのでサンプルとしてとても良いものとは思えないけど、雰囲気を味わうだけでもということで実装。

内容としてはとても濃いのでちゃんと理解しないとね。