#concept string vs concept string view

1 messages · Page 1 of 1 (latest)

quaint depotBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

tired snow
#

yeah you can chain them together to make complicated checks a single constraint, or you can also make them variadic pretty easily, especially when mixed with folds

tired snow
#

what

#

here's what i meant by the variadic bit:

 template <typename T, typename... TOther>
 concept any_of = (std::same_as<std::type_identity_t<T>, TOther> || ...);
#

so then you can just do stuff like:

static_assert(any_of<int, float, double, char, whatever>);
#

and if the first param matches any of the others it'll evaluate to true

acoustic thunder
#

What do you mean by Like?
E.g. if you want something that's convertible to that type, then there'd be std::convertible_to, or if you want not only a similar but the exact type you could use std::same_as.

quaint depotBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

acoustic thunder
#

A similar example is given on the std::same_as cppref page in the code example:

template<typename T, typename ... U>
concept IsAnyOf = (std::same_as<T, U> || ...);

The ... on the right of the || is a fold expression.

Now @tired snow what I didn't understand is why you added the std::type_identity_t in your code. Could you please explain?

tired snow
#

it's not actually needed for the example... i think it simplified getting some code to build that was kind of convoluted or something along those lines by helping with the type deduction. it was just some hacked together code i think, but i don't really remember since i just grabbed that example from one of my repos.