A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../ranges/contiguous_range.html below:

std::ranges::contiguous_range - cppreference.com

The contiguous_range concept is a refinement of range for which ranges::begin returns a model of contiguous_iterator and the customization point ranges::data is usable.

[edit] Semantic requirements

T models contiguous_range only if given an expression e such that decltype((e)) is T&, std::to_address(ranges::begin(e)) == ranges::data(e).

[edit] Example
#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 being a ranges::contiguous_range doesn't have to be a 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>>>
    );
}
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4