結果の型が文字列入力の値に依存するように、ユーザー定義の文字列リテラル変換演算子を定義することは可能ですか?
ユーザー定義の整数リテラルと浮動小数点リテラルは、リテラル演算子テンプレートを受け入れ、リテラルの実際の文字がテンプレート引数として渡されるため、簡単です。例:
template <char... s> struct silly { using type = int; };
template <char... s> struct silly<'1', s...> { using type = double; };
template <char... s>
typename silly<s...>::type operator"" _silly() { return 0; }
static_assert(std::is_same<int, decltype(4321_silly)>::value, "no luck");
static_assert(std::is_same<double, decltype(1234_silly)>::value, "no luck");
ユーザー定義の文字列リテラルにはそのようなものは存在しないようです。
現在の標準で、または将来の改訂で計画/議論されている、おそらくこれを行う別の方法はありますか?