Namespaces
Variants

std::ranges::contiguous_range

cppreference.net에서
 
 
범위 라이브러리
범위 어댑터
 
헤더에 정의됨<ranges>
template< class T >
concept contiguous_range =
    ranges::random_access_range<T> &&
    std::contiguous_iterator<ranges::iterator_t<T>> &&
    requires(T& t) {
        { ranges::data(t) } ->
            std::same_as<std::add_pointer_t<ranges::range_reference_t<T>>>;
    };
(since C++20)

그contiguous_range개념은range의 세분화이며, 이에 대해ranges::begin은contiguous_iterator의 모델을 반환하고 사용자 정의 지점ranges::data를 사용할 수 있습니다.

의미론적 요구사항

T 는 다음 조건을 만족할 때에만 contiguous_range 를 모델합니다: 표현식 e 가 주어졌을 때 decltype ( ( e ) ) 가 T & 이고, std:: to_address ( ranges:: begin ( e ) ) == ranges:: data ( e ) 일 때.

예제

#include <array>
#include <deque>
#include <list>
#include <mdspan>
#include <ranges>
#include <set>
#include <span>
#include <string_view>
#include <valarray>
#include <vector>
template<typename T>
concept CR = std::ranges::contiguous_range<T>;
// zstring이 ranges::contiguous_range라도 ranges::sized_range일 필요는 없음
struct zstring
{
    struct sentinel
    {
        friend constexpr bool operator==(const char* str, sentinel) noexcept
        { return *str == '\0'; }
    };
    const char* str;
    const char* begin() const noexcept { return str; }
    sentinel end() const noexcept { return {}; }
};
int main()
{
    int a[4];
    static_assert(
            CR<std::vector<int>> and
        not CR<std::vector<bool>> and
        not CR<std::deque<int>> and
            CR<std::valarray<int>> and
            CR<decltype(a)> and
        not CR<std::list<int>> and
        not CR<std::set<int>> and
            CR<std::array<std::list<int>,42>> and
            CR<std::string_view> and
            CR<zstring> and
            CR<std::span<const int>> and
        not CR<std::mdspan<int, std::dims<1>>>
    );
}

참고 항목

범위가 자신의 크기를 상수 시간에 알 수 있음을 명시
(concept)
반복자 타입이 random_access_iterator 를 만족하는 범위를 명시
(concept)