Let's say I have a struct Foo
and I want to determine if Foo
has an int
inside of it.
struct Foo { int a; char c; };
has_int<Foo>::value; // should be true
This is the most basic form of what I'd actually want, checking for a specific type:
has_type<Foo, int>::value;
If I knew how to do the above I could transform it to what my end goal is:
has_pointer<Foo>::value; // false
struct Bar { int a; void *b; };
has_pointer<Bar>::value; // true
As for what I've tried, it's hard to get started, the best I can think of is that if I could get a pack of the types contained in a struct, I could write the rest:
template <typename... Ts>
constexpr bool any_is_pointer() noexcept {
return (... || std::is_pointer_v<Ts>);
}
What I'm asking for seems like it may very well be impossible. I couldn't find a duplicate, but I was surprised that I couldn't so it might be out there.
Aucun commentaire:
Enregistrer un commentaire