Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::contiguous_range

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      Defined in header<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)

      Thecontiguous_range concept is a refinement ofrange for whichranges::begin returns a model ofcontiguous_iterator and the customization pointranges::data is usable.

      [edit]Semantic requirements

      T modelscontiguous_range only if given an expressione such thatdecltype((e)) isT&,std::to_address(ranges::begin(e))==ranges::data(e).

      [edit]Example

      Run this code
      #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_rangestruct zstring{struct sentinel{friendconstexprbool operator==(constchar* str, sentinel)noexcept{return*str=='\0';}}; constchar* str; constchar* begin()constnoexcept{return str;}    sentinel end()constnoexcept{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<constint>> and        not CR<std::mdspan<int,std::dims<1>>>);}

      [edit]See also

      specifies that a range knows its size in constant time
      (concept)[edit]
      specifies a range whose iterator type satisfiesrandom_access_iterator
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/contiguous_range&oldid=177508"

      [8]ページ先頭

      ©2009-2025 Movatter.jp