2

我发现这typename gsl::span<const gsl::byte>::const_iterator不满足Readablerange-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_tconst从 the中删除value_type,然后它们就不一样了。

CommonReference约束是什么意思?为什么要Readable满足他们?

4

1 回答 1

2

您的问题出在 GSL 中。来自span_iteratorhttps://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-qualified也是如此value_type。这是奇怪和错误的。它可能也不符合标准。我尚未在该断言的标准中找到明确的证据,但该标准具有很强的暗示性。例如,这里是std::iterator_traitsfor 指向 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

于 2016-12-08T22:12:03.993 回答