C++范围 TS 包括实验路径

C++ Ranges TS include experimental path

本文关键字:实验 路径 包括 TS 范围 C++      更新时间:2023-10-16

我想使用C++范围。工作草案,C++范围的扩展 说:

The Ranges library provides the Ranges library headers, shown in Table 2.
Table 2 — Ranges TS library headers
<experimental/ranges/algorithm>   <experimental/ranges/random>
<experimental/ranges/concepts>    <experimental/ranges/tuple>
<experimental/ranges/functional>  <experimental/ranges/utility>
<experimental/ranges/iterator>

我发现的最接近的是 Range-v3 - 标准库的范围算法、视图和操作,上面写着:

Range library for C++11/14/17. This code is the basis of a formal proposal to add range support to the C++ standard library.
This library is header-only. You can get the source code from the range-v3 repository on github. To compile with Range-v3, you can either #include the entire library:
#include <range/v3/all.hpp>
Or you can #include only the core, and then the individual headers you want:
#include <range/v3/core.hpp>
#include <range/v3/....

解释Range TS与"实验性"和Range V3之间包含的差异。在哪里可以找到带有"实验/范围"的范围?意义何在,重要吗?这应该是控制它的编译器选项吗?

范围 TS 是一个C++的技术规范。默认情况下,TS 中任何库功能的任何标头都以"实验性"为前缀,并且这些标头包含的任何内容都将进入命名空间std::experimental

Range-v3 是一个C++,它实现了与范围相关的各种功能。但它没有做的是实现范围 TS 本身。也就是说,它不是 TS 的正式实现。因此,它可以将其标题放在任何它喜欢的地方;它不受 TS 规则的约束。

如果编译器实现了 Ranges TS,则可以在文档中查看访问它所需的编译器开关(如果有(。由于范围 TS 是针对概念 TS 编写的,因此您可能至少需要激活它。如果您下载了独立的 Ranges TS 实现,那么文档将(希望(告诉您如何使用它。

Range-v3

早于 Range TS,TS 中的功能基于 range-v3 的功能(并且是其子集(。范围 TS 需要一个支持概念 TS 的编译器;range-v3 没有,因此 range-v3 不可能是 TS 实现。

如果您正在寻找 Ranges TS 的参考实现,请在 GitHub 上找到 cmcstl2 项目。