如何用 std::is_same 替换 std::is_same_v [英] How to replace std::is_same_v with std::is_same

查看:47
本文介绍了如何用 std::is_same 替换 std::is_same_v的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个包含 std::is_same_v 的代码可用于 C++17.但由于工具链的限制,我一直坚持使用 C++14.

I have this code containing std::is_same_v available with C++17. But I've stuck with C++14 due to toolchain limitation.

template<class T, class O = T>
using IteratorOnly = std::enable_if_t<
    !std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O
>;

如何将 std::is_same_v 替换为 std::is_same?是否有任何解决方法可以仅使用 C++14 编译代码?

How can I replace std::is_same_v with std::is_same? Is there any workaround to be able to compile the code with just C++14?

推荐答案

该错误已由@Someprogrammerdude 注释解决,该注释关于 is_same_v helper 变量模板 已定义 此处.我的最终代码是

The error got resolved by @Someprogrammerdude comment about a is_same_v helper variable template defined here. My final code is

#ifdef My_OLD_TOOL_CHAIN

template< class T, class U >
inline constexpr bool is_same_v = std::is_same<T, U>::value;

template<class T, class O = T>
using IteratorOnly = std::enable_if_t<
    !is_same_v<typename std::iterator_traits<T>::value_type, void>, O
>;

#else // My_OLD_TOOL_CHAIN

template<class T, class O = T>
using IteratorOnly = std::enable_if_t<
    !std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O
>;

#endif // My_OLD_TOOL_CHAIN

这篇关于如何用 std::is_same 替换 std::is_same_v的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆