Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #70340
| From | Soviet_Mario <SovietMario@CCCP.MIR> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: enum type in template declaration |
| Date | 2019-12-07 18:57 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <qsgp75$lhp$1@dont-email.me> (permalink) |
| References | <qsbvs3$81l$1@dont-email.me> <4626047e-db85-4979-b2de-e36bd0955a02@googlegroups.com> |
Il 07/12/19 10:53, saturnman2008@gmail.com ha scritto:
> 在 2019年12月6日星期五 UTC+8上午6:21:05,Soviet_Mario写道:
>> since what version of standard, if any, an ENUM type can be
>> an argument of a template ?
>>
>> sth like
>>
>> enum class RestrictedValues { A = 1, B = 2, C = 4, D = 8 };
>>
>>
>> template <RestrictedValues ttVal> class SizedField
>> {
> public:
> static constexpr int aSize = static_cast<int>(ttVal);
>> private:
>
>> unsigned char zzArray [aSize];
Yes it was a slight of mine to not have converted an enum to
int explicitely.
But the main question was not about that.
Anyway they have just reassured me that the compiler checks
for invalid non-forced cast in the reverse sense (from a
generic integer to the enum) in the specialization of an
instance. That was the source of my concern.
The forced manual cast did not worry me, I try not to shoot
in my foot :)
>>
>>
>> public:
>>
>> etc etc
>>
>> }
>>
>>
>> or if the syntax is wrong, how to workaround ?
>>
>> The goal is to have a template depending on a restricted
>> well defined, and known at compile time, set of integral values
>>
>>
>>
>> enum RestrictedValues { A = 1, B = 2, C = 4, D = 8 };
>
>
> template <RestrictedValues ttVal> class SizedField
> {
> private:
> unsigned char zzArray [ttVal];
>
>
> public:
>
> etc etc
>
> }
>>
>>
>>
>> --
>> 1) Resistere, resistere, resistere.
>> 2) Se tutti pagano le tasse, le tasse le pagano tutti
>> Soviet_Mario - (aka Gatto_Vizzato)
>
>
> If my modification fits your requirement?
>
--
1) Resistere, resistere, resistere.
2) Se tutti pagano le tasse, le tasse le pagano tutti
Soviet_Mario - (aka Gatto_Vizzato)
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-05 23:20 +0100
Re: enum type in template declaration James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-12-05 22:39 -0500
Re: enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-06 13:15 +0100
Re: enum type in template declaration Paavo Helde <myfirstname@osa.pri.ee> - 2019-12-06 14:42 +0200
Re: enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-06 17:20 +0100
Re: enum type in template declaration Paavo Helde <myfirstname@osa.pri.ee> - 2019-12-06 20:29 +0200
Re: enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-06 22:42 +0100
Re: enum type in template declaration Paavo Helde <myfirstname@osa.pri.ee> - 2019-12-07 00:51 +0200
Re: enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-07 18:54 +0100
Re: enum type in template declaration Öö Tiib <ootiib@hot.ee> - 2019-12-06 06:00 -0800
Re: enum type in template declaration James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-12-06 09:56 -0500
Re: enum type in template declaration Manfred <noname@add.invalid> - 2019-12-06 15:56 +0100
Re: enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-06 18:43 +0100
Re: enum type in template declaration saturnman2008@gmail.com - 2019-12-07 01:53 -0800
Re: enum type in template declaration Soviet_Mario <SovietMario@CCCP.MIR> - 2019-12-07 18:57 +0100
csiph-web