From the course: Functional Programming in C++

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Defining custom concepts

Defining custom concepts - C++ Tutorial

From the course: Functional Programming in C++

Defining custom concepts

- [Instructor] Defining custom concepts. While the standard library provides beneficial traits such as std::is_arithmetic, std::is_integral, et cetera, you can create your own concepts using requires expressions. So let's go ahead and get started here. So we're going to start off here right underneath where it says with a template, hit space, and then typename and a T. Okay, and we're going to have a concept and we're going to call it Iterable, and it's going to equal requires(T t), big T and little t. And by the way, these Ts that I'm using, you can use whatever letter of the alphabet suits your fancy, but T is just sort of tradition. And then we're going to have another opening brace, and we're going to say t.begin and a closing curly brace, an arrow and an std::same_as<decltype, and then we're going to have a t.end, open and closing braces, closing parameter, and a closing. So what this piece of code is doing is it's looking to make sure that anything you pass in as t has both a…

Contents