jeudi 27 février 2020

Using concepts for checking if a type T has a field F

The following concept checks if a type T has a public field foo:

template<typename T>               
concept has_field_foo = requires { 
    T::foo;                       
}

Is there a way to implement a generic concept that would check if a type T has a public field F, something like (pseudo code... the field F cannot be passed like this):

template<typename T, typename F>               
concept has_field = requires { 
    T::F;
}




Aucun commentaire:

Enregistrer un commentaire