C++ Logo


Advanced search

Subject: Re: [std-proposals] "Union types" syntactic sugar
From: Sebastian Büttner (sebastian.buettner_at_[hidden])
Date: 2020-03-04 08:23:32

What's wrong with that (sorry for the terrible name):

    template<typenameT, typename... Us>
    conceptany_of = (std::is_same_v<T, Us> || ...);

    voidf(any_of<char, uint8_t> autox);

    template<any_of<char, uint8_t> T>
    voidf(std::basic_string<T> x);


No series of is_same_v needed and you can reuse it, so no need for
inventing weird names if you are worried about that...


On 04.03.20 15:12, Michał Piotr Gawron via Std-Proposals wrote:
> On 04.03.2020 15:03, Михаил Найденов wrote:
>> Well,
>> template<class T>
>> concept charOrUInt8 = std::is_same_v<char> || std::is_same_v<uint8_t>;
>> void f (charOrUInt8 auto x);
>> template<charOrUInt8 T>
>> void f (std::basic_string<T> x)
>> Close enough, if ask me :)
> That still requires writing a series of std::is_same_v<> but this time
> I'd also have to invent a name for the concept. I'd like to avoid that
> and keep the actual list of types right in the arguments list. Of
> course, if I wanted to reuse the allowed types list, I'd use a concept.

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups