Back to results for “Templates”
C++ › Concepts & Constraints

How do concepts interact with the ranges library?

Advanced

Answer

The ranges library is built on concepts: it defines iterator and range concepts (input_iterator, sized_range, etc.) that constrain every algorithm and view, so misuse is caught at compile time with clear messages, and adaptors compose only with compatible ranges. Concepts are foundational to ranges' safety and expressiveness.
Real-world example A view adaptor that needs a forward range fails to compile clearly when given a single-pass input range.

Common follow-ups: What concepts underpin ranges? | How do they make ranges safer?