我发现typename gsl::span<const gsl::byte>::const_iterator
不满足Readable
range-v3 中的概念。在仔细研究了这个概念之后,我发现了这个约束:
template<typename I>
auto requires_(I&&) -> decltype(
concepts::valid_expr(
// The value, reference and rvalue reference types are related
// through the CommonReference concept.
concepts::model_of<CommonReference, reference_t<I> &&, value_t<I> &>(),
concepts::model_of<CommonReference, reference_t<I> &&, rvalue_reference_t<I> &&>(),
concepts::model_of<CommonReference, rvalue_reference_t<I> &&, value_t<I> const &>(),
// Experimental additional tests. If nothing else, this is a good workout
// for the common_reference code.
concepts::model_of<Same, ranges::common_reference_t<reference_t<I>, value_t<I>>, value_t<I>>(),
concepts::model_of<Same, ranges::common_reference_t<rvalue_reference_t<I>, value_t<I>>, value_t<I>>()
));
ranges::common_reference_t
删除const
来自value_type
然后它们就不一样了。
CommonReference
有什么作用?约束是什么意思?为什么要Readable
满足他们吗?
最佳答案
您的问题出在 GSL 上。来自 span_iterator
的来源(https://github.com/Microsoft/GSL/blob/master/gsl/span#L145-L147):
using value_type =
std::conditional_t<IsConst, std::add_const_t<typename Span::element_type>,
typename Span::element_type>;
所以span::const_iterator
有一个const
-合格value_type
。这很奇怪而且错误。它可能也不符合标准。我尚未在标准中找到该断言的明确证据,但该标准具有很强的启发性。例如,这里是 std::iterator_traits
的特化对于指向 const 的指针:
template<class T> struct iterator_traits<const T*> {
using difference_type = ptrdiff_t;
using value_type = T;
using pointer = const T*;
using reference = const T&;
using iterator_category = random_access_iterator_tag;
};
看到了吗? value_type
不是const
- 限定,即使是指向 - const
的指针.
关于c++ - Range-v3 中 Readable 使用的 CommonReference 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41014661/