gpt4 book ai didi

c++ - 无法创建具有值和绑定(bind)的 std::ranges::iota_view

转载 作者:行者123 更新时间:2023-12-04 08:29:40 25 4
gpt4 key购买 nike

我试图创建一个 std::ranges::iota_view有一个值和一个界限:

#include <ranges>
#include <vector>

int main() {
std::vector v{1,2,3};
auto indices = std::ranges::views::iota(0, v.size());
}

link to program on godbolt

但是 clang 11.0.0 编译失败,报错信息:

no viable constructor or deduction guide for deduction of template arguments of 'iota_view'

我做错了什么?

最佳答案

来自 https://en.cppreference.com/w/cpp/ranges/iota_view

Note that the [deduction] guide protects itself against signed/unsigned mismatch bugs, like views::iota(0, v.size()), where 0 is a (signed) int and v.size() is an (unsigned) std::size_t.

这会起作用:

auto indices = std::ranges::views::iota(0u, v.size());
^ unsigned zero literal

不幸的是,Clang 似乎还有另一个错误,但它 works in gcc ;或者你可以 use range-v3 .

关于c++ - 无法创建具有值和绑定(bind)的 std::ranges::iota_view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65089262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com