What's the best way to restrict the function parameter?

Viewed 52

I decided to develop a library in Cpp. The code will also be visible and changable for users.

So which of the following is a better way to go when I need to restrict parameters to have a specific function?

method 1:

#include <concepts>
class base{
    virtual void spec_func() = 0;
};

template<typename T>
concept Con1 = std::derived_from<T, base>;

template<Con1 T>
void use_func(T);

method 2:

template<typename T>
concept Con2 =
requires(T arg) {
    arg.spec_func();
};

template<Con2 T>
void use_func(T);

Or neither of them?

0 Answers
Related