Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to remove reference, cv qualifiers, and pointerness of a type to make it plain?

Take the following code:

struct Foo {}

template<typename T>
void passFoo(T t) {}

I would want the domain of passFoo to be restricted to Foo objects, but I don’t mind if they are references, pointers, or cv qualified. Is it possible to somehow remove all those aspects of a type to get down to the "plain" type, when using a concept? For instance:

template<typename T>
concept Foo_C = std::is_same_v<Foo, plainify<T>>;

template<Foo_C Foo_c>
void passFoo(Foo_c foo) {}

In that hypothetical code, passFoo could accept only Foo, Foo&, Foo*, const Foo, etc. Is there any actual way to do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Combination of std::remove_cvref_t and std::remove_pointer_t would work:

template<typename T>
concept Foo_C = std::is_same_v<Foo, std::remove_cvref_t<std::remove_pointer_t<T>>>;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading