我想从字符串文字创建一个模板类: create_eq(" abcdefg")获取IEqual<' a'' b'' c'' d' ' E'> 但ISO C ++ 11的用户定义文字只支持整数文字和浮动文字:
template<char... Chars>
IEqual<Chars...> operator "" _suffix()
{
return {};
}
auto a=3423134_suffix;//yes
auto b="abcdef"_suffix;//error!
我试试
using Char=int;
template<Char...ARGS>
class IEqual
{
public:
};
template<unsigned... I> struct Index{};
template<unsigned N, unsigned... I>
struct GenIndex : GenIndex<N-1, N-1, I...>{};
template<unsigned... I>
struct GenIndex<0, I...> : Index<I...>{};
template<unsigned I>
constexpr Char pos(const char*a)
{
return a[I];
}
template<unsigned...I>
constexpr auto eq(Index<I...> ,const char*a)
->decltype(IEqual<(pos<I>(a))...>())// this error
{
return {};
}
template<unsigned N>
constexpr auto eq(const char(&a)[N])
->decltype(eq(GenIndex<N>{},a))
{
return eq(GenIndex<N>{},a);
}
所以我该怎么做?