std::ranges::contiguous_range(3cxx)

πŸ“¦
version 16-20260322 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– std::ranges::contiguous_range β€” the libstdc++ glow-up, manual section 3cxx ✨

okay bestie, pull up a chair because we're about to talk about one of the most lowkey iconic concepts in <ranges>. it's std::ranges::contiguous_range, it lives in the libstdc++ manual (section 3cxx), and it's literally just out here being the range that knows its own memory is laid out all in a row. no cap.


🌸 NAME 🌸

std::ranges::contiguous_range β€” a range for which ranges::begin returns a contiguous iterator. that's it, that's the whole personality. πŸŽ€


✨ SYNOPSIS ✨

she's a concept, so you don't call her, you satisfy her. first, the include:

#include <ranges>

πŸ¦‹ Concept definition πŸ¦‹

here's the exact definition, character for character, because we do not play with the source code:

template<typename _Tp>
concept std::ranges::contiguous_range =  random_access_range<_Tp> && contiguous_iterator<iterator_t<_Tp>>
      && requires(_Tp& __t)
      {
        { ranges::data(__t) } -> same_as<add_pointer_t<range_reference_t<_Tp>>>;
      }

like… look at her. three little requirements, all vibes, all correct. πŸ’…


πŸ’œ Detailed Description πŸ’œ

a range for which ranges::begin returns a contiguous iterator.

that's the tea, that's the whole thing. if ranges::begin hands you back a contiguous iterator, congrats, your range is a contiguous_range. the elements are sitting right next to each other in memory like besties in a group photo. πŸ“Έβœ¨

ok but real talk β€” this is a concept, so it's a compile-time vibe check, not a runtime thing. if it doesn't hold, your code doesn't compile. no takebacks. πŸ’€

πŸ‘‘ Author πŸ‘‘

generated automatically by Doxygen for libstdc++ from the source code. so like, no human wrote this one, it's giving main character energy from a documentation generator. iconic honestly. πŸ€–πŸ’–


and that's the page, bestie! 🫢 source and version: libstdc++, manual section 3cxx, as the footer of this page says β€” so if you ever forget where you read this, it was libstdc++ the whole time. slay, go satisfy some concepts, and remember: contiguous memory is a love language. πŸŒˆπŸ’œβœ¨

πŸ“¦ where this page comes from