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. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, and your progress syncs across the web and the CoddyKit app. The C++ Academy course includes 4 lessons in total.
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.
Learn C++ with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 51
- Lessons
- 203
Frequently Asked Questions
Is the “Common Standard Concepts Integral Ranges” lesson free?
Yes — any 3 lessons of the C++ Academy learning path, including “Common Standard Concepts Integral Ranges”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The C++ Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
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