当我查看有关GCC 8的新闻时,我看到他们增加了对2017版C语言的支持(不是C++ 17,真的是C17).但我在互联网上找不到任何关于它的信息.
它是像C11这样的新ISO版本,还是GCC团队用于编译器中某些更正的代号?
我实际上在Visual Studio 2017(Visual C++ 14.15.26706)上用C++ 17中的lambdas进行了一些测试.下面的代码非常有效.
#include <iostream>
int main()
{
bool const a_boolean { true };
int const an_integer { 42 };
double const a_real { 3.1415 };
auto lambda = [a_boolean, an_integer, a_real]() -> void
{
std::cout << "Boolean is " << std::boolalpha << a_boolean << "." << std::endl;
std::cout << "Integer is " << an_integer << "." << std::endl;
std::cout << "Real is " << a_real << "." << std::endl;
};
lambda();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我的一个朋友在Qt Creator上测试了一个现代的MinGW,我也做了,我们都得到两个相同代码的警告而不是珍贵. …
我实际上是在尝试通过编写自己的小模块来理解 C++20 模块系统。假设我想提供一个函数来删除字符串开头和结尾的所有空格(一个trim
函数)。下面的代码工作没有问题。
module;
export module String;
import std.core;
export std::string delete_all_spaces(std::string const & string)
{
std::string copy { string };
auto first_non_space { std::find_if_not(std::begin(copy), std::end(copy), isspace) };
copy.erase(std::begin(copy), first_non_space);
std::reverse(std::begin(copy), std::end(copy));
first_non_space = std::find_if_not(std::begin(copy), std::end(copy), isspace);
copy.erase(std::begin(copy), first_non_space);
std::reverse(std::begin(copy), std::end(copy));
return copy;
}
Run Code Online (Sandbox Code Playgroud)
import std.core;
import String;
int main()
{
std::cout << delete_all_spaces(" Hello World! \n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是如果我只想使用特定的头文件而不是std.core
在我的模块中呢?如果这样做,将 替换为import std.core
以下代码,我会在 Visual Studio 2019 上收到错误消息。
module;
#include <algorithm> …
Run Code Online (Sandbox Code Playgroud)