Defining Interfaces in C++: Concepts Versus Inheritance -- Daniel Lemire
In 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() };
};

Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Every year we run Pure Virtual C++: a free one-day virtual conference for the whole C++ community. Next month we’re doing it again!
This conference is organized by the C++ Community for the C++ Community. We want the whole community to be represented. We especially encourage those who identify as coming from an underrepresented community to apply to present and to be present. Presenting a talk is not limited to previous presenters or previous attendees.
The submission deadline is June 25th, with decisions sent by July 31st.
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held 