入力を string または double に変換するための型特性が必要です。今、私はこのようなものを持っています:
template<typename T> struct SH_trait{ };
template<> struct SH_trait<float>{ typedef double type; };
template<> struct SH_trait<double>{ typedef double type; };
template<> struct SH_trait<char*>{ typedef std::string type; };
template<> struct SH_trait<const char*>{ typedef std::string type; };
template<std::size_t N> struct SH_trait<const char[N]> { typedef std::string type; };
template<std::size_t N> struct SH_trait<char[N]> { typedef std::string type; };
template<> struct SH_trait<std::string>{ typedef std::string type; };
template<> struct SH_trait<TString>{ typedef std::string type; };
そして私はそれを
void f(T input) {
SH_trait<T>::type myvalue(input);
Class template_class(myvalue);
...
}
double
template_class はandだけに特化しているのでやっていstring
ます。
ポイントは、ユーザーがたとえばを使用するとしますint
。double に変換したいので、もう 1 行追加する必要があります。すべてのケースをカバーするために、より一般的なものを書くことは可能ですか?
C++11 なし、Boost なし、C++03 のみ