Joseph Garvin
Joseph Garvin

Reputation: 21974

How to have a single parameter concept enforce presence of a templated method?

I can write the following:

template<class T, class U>
concept foo = requires(T& t) {
    { t.template bar<U>() } -> std::same_as<void>;
};

The only problem is that this gives me a concept foo<T, U> and what I want is a concept foo<T>. I don't want a concept that asserts that T has a method called bar that takes some specific U, I want to assert that T has a method called foo that is templated and thus can accept anything. Syntax I just made up:

template<class T>
concept foo = requires(T& t) {
    template<class U> { t.template bar<U>() } -> std::same_as<void>;
};

Is more like what I'm trying to achieve. Can this be done in C++23?

Note for reopening: the other question doesn't address the single-parameter aspect of my question at all (the part that is right in the title)

Upvotes: 1

Views: 66

Answers (0)

Related Questions