Namespaces
Variants

std::ranges:: contiguous_range

From cppreference.net
Ranges library
Range adaptors
헤더에 정의됨 <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 >>> ;

} ;
(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)