c++ - 启用 c++17 时 __cplusplus 的奇怪输出
问题描述
我在这里用元编程做一些实验,最初的想法是找出我们是否可以在编译时使排序的整数序列唯一。(虽然这与问题无关)
我在我的属性中启用了 c++17(我使用 VS2019),当我想找出 C++ 标准时,这个程序给了我奇怪的输出。
#include <iostream>
#include <boost/mp11.hpp>
#include <type_traits>
namespace
{
template <int... N>
using seq = boost::mp11::mp_list_c<int, N...>;
template <int... N>
struct uniq
{
using type = boost::mp11::mp_unique<seq<N...>>;
};
}
int main()
{
static_assert(std::is_same_v<uniq<1, 2, 2, 2, 3, 3, 3>::type, seq<1, 2, 3>>,"Assertion Failed");
static_assert(std::is_same_v<uniq<4, 1, 9, 9, 2, 2, 3, 1, 5>::type, seq<4, 1, 9, 2, 3, 5>>,"Assertion Failed");
if (__cplusplus == 201703L) std::cout << "C++17\n";
else if (__cplusplus == 201402L) std::cout << "C++14\n";
else if (__cplusplus == 201103L) std::cout << "C++11\n";
else if (__cplusplus == 199711L) std::cout << "C++98\n";
else std::cout << "pre-standard C++\n";
return 0;
}
这会打印“C++98”,我想知道这是怎么回事?我已经从属性中启用了 c++17,并且我显然使用了一些比 c++98 更高级的语言功能(如可变参数模板)。
这会给任何人敲响警钟吗?我会想念什么吗?
解决方案
在 Visual Studio 中,您必须启用/Zc:__cplusplus
才能获得适当的值。
这与向后兼容性有关。
推荐阅读
- sql-server - 如何将 COUNT 添加到包含案例的子查询中
- javascript - JS 图像库 - 将图像附加到灯箱以进行全屏预览
- html - 剪辑路径的替代方法:Internet Explorer 8 中的 inset()
- javascript - 如何在不使用数据库的情况下在html页面中单击提交按钮时显示表单数据
- powershell - Powershell - 将文件移动1个文件夹更深
- python - 计算列表列表的平均值
- amazon-web-services - AWS 队列在响应中不返回 MessageAttributeNames
- ruby-on-rails - Rails 4 范围连接以查找非此即彼的关系
- aspnetboilerplate - 如何在 ASP.NET 样板中更改侧边栏菜单项的图标?
- eclipse - 流程建模和流程开发透视图在 Eclipse 中不可见