小编inf*_*ero的帖子

什么是C17以及该语言有哪些变化?

当我查看有关GCC 8的新闻时,我看到他们增加了对2017版C语言的支持(不是C++ 17,真的是C17).但我在互联网上找不到任何关于它的信息.

它是像C11这样的新ISO版本,还是GCC团队用于编译器中某些更正的代号?

c gcc iso c11 c17

60
推荐指数
2
解决办法
2万
查看次数

为什么我只为bool和int得到-Wunused-lambda-capture而不是double?

我实际上在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++ lambda c++17

8
推荐指数
0
解决办法
109
查看次数

在 C++20 中混合模块和头文件是否可能/可接受?

我实际上是在尝试通过编写自己的小模块来理解 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)

c++ c++20 c++-modules

6
推荐指数
1
解决办法
423
查看次数

标签 统计

c++ ×2

c ×1

c++-modules ×1

c++17 ×1

c++20 ×1

c11 ×1

c17 ×1

gcc ×1

iso ×1

lambda ×1