How to define a concept that is satisfied by an arbitrary std::vector?
I would like to have a concept requiring as return type an arbitrary vector:
template<typename T>
concept HasVector = requires (T t) {
{ T.vec() } -> std::same_as<std::vector<int>>; //works
{ T.vec() } -> std::same_as<std::vector<foo>>; //want to put something arbitrary in here
}
Such that we would have something like the following:
class A {
std::vector<int> vec() { /* ... */}
}
class B {
std::vector<double> vec() { /* ... */}
}
static_assert(HasVector<A>);
static_assert(HasVector<B>);
Moreover, it would be even nicer to require as return type a vector whose value type satisfies some other concept, i.e.
template<typename T>
concept Arithmetic = // as in the standard
template<typename T>
concept HasArithmeticVector = requires (T t ) {
{ T. vec() } -> std::same_as<std::vector<Arithmetic>>;
Is there any such way to put this in names of concepts?
from Recent Questions - Stack Overflow https://ift.tt/3iKoFXF
https://ift.tt/eA8V8J
Comments
Post a Comment