Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #87758
| From | Muttley@dastardlyhq.com |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: How can I get the type in a C++17 fold function? |
| Date | 2022-12-08 15:45 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <tmt0rd$1fku$1@gioia.aioe.org> (permalink) |
| References | <tmsbtq$fp6$1@gioia.aioe.org> <c0e8be5f-5276-4de7-9581-1a91982a4501n@googlegroups.com> |
On Thu, 8 Dec 2022 04:45:54 -0800 (PST)
=?UTF-8?B?w5bDtiBUaWli?= <ootiib@hot.ee> wrote:
>On Thursday, 8 December 2022 at 11:49:01 UTC+2, Mut...@dastardlyhq.com wrote:
>> eg:
>>
>> template<typename... T>
>> auto sum(T&&... args)
>> {
>> if (typeid(T) == typeid(string)) { do something }
>> return (args + ...);
>> }
>>
>> However doing typeid on T gives
>>
>> error: expression contains unexpanded parameter pack 'T'
>>
>> in clang.
>>
>> Is there a way to get the type inside the function?
>
>There are too lot of ways but I usually check the types in enable_if
>as I've used to see that and all compilers can already process that.
>If needed I make checking templates myself.
>
>#include <iostream>
>#include <string>
>
>// make checking for char array type
>template <class> struct is_bounded_char_array : std::false_type {};
>template <size_t N> struct is_bounded_char_array<char[N]> : std::true_type {};
>
>// if not std::string, char* and char array
>template<typename T,
> std::enable_if_t<
>!std::is_same_v<std::string, T>
> && !std::is_same_v<char*, T>
> && !is_bounded_char_array<T>{}
> , bool> = true>
>// return whatever it is without processing
>auto process_value(T const& v) {return v;}
Clearly you know more about the dustier corners of C++ than me. enable_if is
the only one of those tests I've heard of.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-08 09:48 +0000
Re: How can I get the type in a C++17 fold function? Juha Nieminen <nospam@thanks.invalid> - 2022-12-08 12:18 +0000
Re: How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-08 15:41 +0000
Re: How can I get the type in a C++17 fold function? Juha Nieminen <nospam@thanks.invalid> - 2022-12-09 12:57 +0000
Re: How can I get the type in a C++17 fold function? Öö Tiib <ootiib@hot.ee> - 2022-12-08 04:45 -0800
Re: How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-08 15:45 +0000
Re: How can I get the type in a C++17 fold function? Öö Tiib <ootiib@hot.ee> - 2022-12-08 13:59 -0800
Re: How can I get the type in a C++17 fold function? Vir Campestris <vir.campestris@invalid.invalid> - 2022-12-14 10:42 +0000
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-14 18:02 +0100
Re: How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-14 17:17 +0000
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-14 18:23 +0100
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-15 17:59 +0100
Re: How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-15 17:20 +0000
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-15 18:37 +0100
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-16 05:26 +0100
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-16 05:41 +0100
Re: How can I get the type in a C++17 fold function? scott@slp53.sl.home (Scott Lurndal) - 2022-12-16 15:17 +0000
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-16 18:22 +0100
Re: How can I get the type in a C++17 fold function? scott@slp53.sl.home (Scott Lurndal) - 2022-12-16 17:42 +0000
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-16 19:20 +0100
Re: How can I get the type in a C++17 fold function? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-28 16:41 -0800
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-29 03:40 +0100
Re: How can I get the type in a C++17 fold function? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-28 22:27 -0800
Re: How can I get the type in a C++17 fold function? Paavo Helde <eesnimi@osa.pri.ee> - 2022-12-29 09:36 +0200
Re: How can I get the type in a C++17 fold function? Mason <mason.nobody@gmail.com> - 2022-12-29 17:15 +0000
Re: How can I get the type in a C++17 fold function? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-29 19:11 +0100
Re: How can I get the type in a C++17 fold function? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-12-29 19:58 -0800
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-30 08:09 +0100
Re: How can I get the type in a C++17 fold function? Michael S <already5chosen@yahoo.com> - 2022-12-30 03:27 -0800
Re: How can I get the type in a C++17 fold function? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-30 14:01 +0100
Re: How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-30 15:17 +0000
Re: How can I get the type in a C++17 fold function? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-30 20:04 +0100
Re: How can I get the type in a C++17 fold function? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-12-30 13:54 -0800
Re: How can I get the type in a C++17 fold function? Muttley@dastardlyhq.com - 2022-12-31 15:33 +0000
Re: How can I get the type in a C++17 fold function? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2022-12-30 17:31 +0000
Re: How can I get the type in a C++17 fold function? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-01-02 13:30 -0800
Re: How can I get the type in a C++17 fold function? Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-30 18:36 +0100
csiph-web