【发布时间】:2018-07-24 05:50:42
【问题描述】:
在c++ 20中提出,一些算法是constexpr。
例如:
template< class InputIt, class UnaryPredicate >
bool all_of( InputIt first, InputIt last, UnaryPredicate p );
(since C++11)
(until C++20)
template< class InputIt, class UnaryPredicate >
constexpr bool all_of( InputIt first, InputIt last, UnaryPredicate p );
(since C++20)
虽然我们知道迭代器通常不是 constexpr。我认为这仅在 constexpr 容器的情况下才有用。有人可以澄清我是否遗漏了什么以及我的理解是否正确?
【问题讨论】:
-
迭代器类型是一个模板参数,可以是
your_custom_iterator,它具有允许此函数为 constexpr 的 constexpr 属性! -
意见问题与堆栈溢出无关。
-
这与意见无关。正如奥利弗提到的一个很好的理由。
-
@code707 这绝对是一种意见。 “真的有用”无法客观回答。即使它是客观的,这个问题对于堆栈溢出来说也太宽泛了,因为全面讨论什么可能使它有用(以及这是否真的有用)将是大量的。
-
@xaxxon..有用可能是合乎逻辑的理由。