We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
template <typename T, typename... List> struct IndexOf;
template <typename T, typename Head, typename... Rest> struct IndexOf<T, Head, Rest...> { enum { value = IndexOf<T, Rest...>::value + 1 }; };
template <typename T, typename... Rest> struct IndexOf<T, T, Rest...> { enum { value = 0 }; };
template struct IndexOf { enum{value = -1}; };
template<typename T, typename...Args> constexpr auto IndexOf_v = IndexOf<T, Args...>::value;
//error:如果不含T类型,返回结果是错误的 IndexOf_v<int, char, char*, double, int64> = 3
template<typename T, typename... Args> constexpr auto IndexOf_v = std::conditional_t<Contains_v<T, Args...>, IndexOf<T, Args...>, std::integral_constant<int32_t, -1>>::value; 我借助Contains模板首先查找是否有匹配的类型,然后再进行IndexOf模板操作来避免这个问题。不知道怎么来修改这个IndexOf模板来直接解决这个不含T类型时的错误问题。你能提供一些帮助吗?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
template <typename T, typename... List>
struct IndexOf;
template <typename T, typename Head, typename... Rest>
struct IndexOf<T, Head, Rest...>
{
enum { value = IndexOf<T, Rest...>::value + 1 };
};
template <typename T, typename... Rest>
struct IndexOf<T, T, Rest...>
{
enum { value = 0 };
};
template
struct IndexOf
{
enum{value = -1};
};
template<typename T, typename...Args>
constexpr auto IndexOf_v = IndexOf<T, Args...>::value;
//error:如果不含T类型,返回结果是错误的
IndexOf_v<int, char, char*, double, int64> = 3
template<typename T, typename... Args>
constexpr auto IndexOf_v = std::conditional_t<Contains_v<T, Args...>,
IndexOf<T, Args...>, std::integral_constant<int32_t, -1>>::value;
我借助Contains模板首先查找是否有匹配的类型,然后再进行IndexOf模板操作来避免这个问题。不知道怎么来修改这个IndexOf模板来直接解决这个不含T类型时的错误问题。你能提供一些帮助吗?
The text was updated successfully, but these errors were encountered: