Defining Interfaces in C++: Concepts Versus Inheritance -- Daniel Lemire

DanielLemire.pngIn a previous blog post, Daniel Lemire showed how you could define ‘an interface’ in C++ using concepts and stated that he did not take into account inheritance as a strategy. He does so here.

Defining Interfaces in C++: Concepts Versus Inheritance

by Daniel Lemire

From the article:

In a previous blog post, I showed how you could define ‘an interface’ in C++ using concepts. For example, I can specify that a type should have the methods has_next, next and reset:

template <typename T>
concept is_iterable = requires(T v) {
                        { v.has_next() } -> std::convertible_to<bool>;
                        { v.next() } -> std::same_as<uint32_t>;
                        { v.reset() };
                      };

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.