#include <ranges> #include <iostream> #include <string_view> using namespace std::literals; int main() { auto fn_is_l = [](...
我在使用 g++ 10.2 编译这段代码。有人知道为什么最后一个 std::views::reverse 在 results3 上会导致编译错误吗? #include <vector> #include <ranges> int main() { auto ...
void foo(const auto& collection) { *collection.begin() = 104; } int main() { std::vector<int> ints {1, 2, 3, 4, 5}; foo(ints...
这是SO Answer的跟进。给定一个扁平的输入范围和三个size_t维度,该代码创建了一个嵌套的random_access_range,其中包含random_access_range的random_access_range模拟了一个三维数组。 Quickbench 使用嵌套的for循环...
当std::views::split()接收到一个未命名的字符串字面值作为模式时,它不会将该字符串分割,但它可以很好地处理未命名字符字面值。 #include <iomanip> #include <iostream> #include <ranges> ...
我想使用C++20的约束算法来实现erase-remove惯用语:std::vector<int> v; v.erase(std::unique(std::begin(v), std::end(v)), std::end(v)); 但是当我进行简单的转换时:v.erase(std:...
以下代码在n为size_t时无法编译通过,但对于int和unsigned则正常工作。 #include <vector> #include <ranges> int main() { size_t n = 1; auto view = std::ra...
#include <vector> #include <ranges> int main() { auto v = std::vector{1, 2, 3, 4}; v | std::views::drop(2); // ok std::vie...
遗留的`std::for_each`函数返回函数,因为标准只要求`Function`满足Cpp17MoveConstructible,根据[alg.foreach]。 template<class InputIterator, class Function> constex...
由于 ranges::view_interface 拥有一个explicit operator bool()函数,这使得大多数C++20范围适配器都能够转换为 bool: https://godbolt.org/z/ccbPrG51cstatic_assert(views::iota(0));...