c++20无限范围/视图编译器错误



所以我看了一段关于c++20新功能的视频(14:30(,想尝试无限范围的功能。

我写了这个代码:

#include <iostream>
#include <cmath>
#include <ranges>
using std::cout;
using std::endl;
bool primeCheck(const int&);
int main()
{
auto ints = std::ranges::view::ints(0);
auto primes {
ints
| std::ranges::views::filter([](const auto& value){ return primeCheck(value); })
| std::ranges::views::take(100)
};
for (auto p : primes)
{
cout << p << endl;
}
return 0;
}
bool primeCheck(const int& value)
{
if (value <= 1) return false;
for (int i = 2; i <= round(sqrt(value)); i++)
{
if (value % i == 0)
{
return false;
}
}
return true;
}

然而,我得到了以下编译器输出:

/bin/sh -c '/usr/bin/make -j4 -e -f  Makefile'
----------Building project:[ InfiniteSequences - Release ]----------
make[1]: Entering directory '/home/paul/Documents/Projects/InfiniteSequences'
/usr/bin/g++-10  -c  "/home/****/Documents/Projects/InfiniteSequences/main.cpp" -std=c++20 -Wall -Wextra -Wpedantic -Wdouble-promotion -Wformat=2 -Wformat-nonliteral -Wformat-signedness -Wformat-y2k -Wnull-dereference -Wimplicit-fallthrough=2 -Wmissing-include-dirs -Wswitch-default -Wunused-parameter -Wuninitialized -Wsuggest-attribute=const -Walloc-zero -Walloca -Wconversion -Wfloat-conversion -Wsign-conversion -Wduplicated-branches -Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow=compatible-local -Wundef -Wunused-macros -Wcast-qual -Wcast-align=strict -Wlogical-op -Wmissing-declarations -Wredundant-decls -Wstack-protector -fstack-protector -pedantic-errors -Werror=pedantic -Werror=char-subscripts -Werror=null-dereference -Werror=init-self -Werror=implicit-fallthrough=2 -Werror=misleading-indentation -Werror=missing-braces -Werror=multistatement-macros -Werror=sequence-point -Werror=return-type -Werror=multichar -DNDEBUG  -o ./Release/main.cpp.o -I. -I.
/home/****/Documents/Projects/InfiniteSequences/main.cpp: In function 'int main(int, char**)':
/home/****/Documents/Projects/InfiniteSequences/main.cpp:14:30: error: expected 'auto' or 'decltype(auto)' after 'view'
14 |     auto ints = std::ranges::view::ints(0);
|                              ^~~~
/home/****/Documents/Projects/InfiniteSequences/main.cpp:14:30: error: 'template<class _Tp> concept std::ranges::view' used without template arguments
make[1]: *** [InfiniteSequences.mk:95: Release/main.cpp.o] Error 1
make[1]: Leaving directory '/home/paul/Documents/Projects/InfiniteSequences'
make: *** [Makefile:5: All] Error 2
====2 errors, 0 warnings====

我从另一个来源(第6页(再次查找了它,我认为它应该有效。

使用

auto ints = std::ranges::views::iota(0);

出于某种原因,视频将其列为view::int,将pdf源列为view::iota,这两个都是错误的。

相关内容

  • 没有找到相关文章

最新更新