staticデータメンバーの明示的特殊化の使い方?


パッと思い浮かんだのが値の初期化とかですかね。

[ソース]

#include <iostream>
#include <string>

template<typename T>
struct X{
    static T value;
};

template<typename T>
T X<T>::value = 42;

template<>
char X<char>::value = 'c';

template<>
float X<float>::value = 3.14f;

template<>
std::string X<std::string>::value = "42";


int
main(){
    std::cout << X<int>::value   << std::endl;
    std::cout << X<short>::value << std::endl;
    std::cout << X<char>::value  << std::endl;
    std::cout << X<float>::value << std::endl;
    std::cout << X<std::string>::value << std::endl;
    return 0;
}

[出力]

42
42
c
3.14
42


これならなんとなく使い道がありそうな雰囲気。