Common Standard Concepts Integral Ranges
Use standard library concepts like integral and ranges::range.
Common Standard Concepts Integral Ranges is a free C++ Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Standard Concept Library
C++20 introduced many standard concepts in <concepts> and <ranges>. Knowing them saves writing your own.
Core Language Concepts
The fundamental concepts:
std::same_as<T, U>std::derived_from<T, U>std::convertible_to<T, U>std::common_with<T, U>std::assignable_from<T, U>
Arithmetic Concepts
Restrict to numeric types:
std::integral— any integer typestd::signed_integral— signed integerstd::unsigned_integral— unsigned integerstd::floating_point— float, double, long double
template <std::floating_point T>
T mean(T a, T b) { return (a + b) / 2; }Comparison Concepts
Constrain types for equality and ordering:
std::equality_comparablestd::totally_orderedstd::three_way_comparable
Object Concepts
Common requirements:
std::movablestd::copyablestd::default_initializablestd::semiregularstd::regular
template <std::regular T>
class Container { /* full-fledged value type */ };Callable Concepts
For functions and functors:
std::invocable<F, Args...>std::regular_invocable<F, Args...>std::predicate<F, Args...>
template <std::invocable<int> F>
void apply_to_42(F&& f) {
std::forward<F>(f)(42);
}Iterator Concepts
In <iterator>:
std::input_iteratorstd::forward_iteratorstd::bidirectional_iteratorstd::random_access_iteratorstd::contiguous_iterator
Ranges Concepts (C++20)
From <ranges>:
std::ranges::range— has begin/endstd::ranges::view— non-owning rangestd::ranges::sized_range— knows its size in O(1)std::ranges::random_access_range
template <std::ranges::range R>
auto first(R&& r) {
return *std::ranges::begin(r);
}Combining Concepts
Mix concepts to express precise requirements.
template <std::ranges::random_access_range R>
requires std::integral<std::ranges::range_value_t<R>>
auto sum(const R& r) {
return std::reduce(std::ranges::begin(r), std::ranges::end(r));
}Custom Concepts on Top
Build domain-specific concepts on top of standard ones.
template <typename T>
concept Number = std::integral<T> || std::floating_point<T>;Concept-Backed Algorithms
C++20 ranges algorithms are heavily concept-constrained. Their error messages directly say which concept failed when you pass an unsuitable type.
Cheat Sheet
Use built-in concepts whenever possible:
- Numbers →
integral/floating_point - Iteration →
ranges::range - Callable →
invocable/predicate - Value type →
regularorsemiregular
Quick Check
Which standard concept describes a type that has both begin() and end()?
Recap
The standard library ships rich concept libraries: arithmetic (integral, floating_point), comparable (equality_comparable), object (movable, regular), invocable, iterator, and range. Use them as the foundation for your own constraints.
Frequently asked questions
Is the “Common Standard Concepts Integral Ranges” lesson free?
Yes — the full text of “Common Standard Concepts Integral Ranges” is free to read here on the web, and the C++ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C++ Academy course, upgrade to CoddyKit PRO.
What will I learn in “Common Standard Concepts Integral Ranges”?
Use standard library concepts like integral and ranges::range. You practise C++ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C++ Academy?
No prior experience is required. C++ Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Common Standard Concepts Integral Ranges” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C++ Academy lesson?
Yes. Every C++ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why Concepts vs SFINAE
- Defining Concepts with requires
- Using Concepts in Templates and auto
- Common Standard Concepts Integral Ranges