Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6766
| From | "MikeP" <mp011011@some.org> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Integer promotions, conversions, coercions and templates :( (Conclusion) |
| Date | 2011-06-15 08:45 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <itaeun$ljn$1@dont-email.me> (permalink) |
| References | <isorvh$sre$1@dont-email.me> <it8r83$4bv$1@dont-email.me> <95qe0uFt6eU4@mid.individual.net> |
Ian Collins wrote:
> On 06/15/11 11:35 AM, MikeP wrote:
>> I opted for a preprocessor macro approach (I used the "super macro"
>> technique) to implement the actual code alluded to by the example. I
>> feel that aberrating the algorithm with C++-isms to make up for the
>> deficiencies in the language is an inferior solution to the macro
>> approach. Remember, that the example was not the actual code (the
>> actual code is a class and the example is indicative of one of the
>> methods of that class), and that the example suffers even more ills
>> caused by the inferior/deficient/incorrect C++ type system. Note
>> that the point was to generate 4 different definitions of the class
>> (function, in the example) for use and not meant to be a template or
>> macro to be used directly.
>
> What your example really suffered from was your unwillingness to use
> the facilities offered by the language.
At first it looked like a good idea because it was brief enough. On
further analysis, though, I realized that compromising the algorithm was
not prudent (for a number of reasons).
>
>> Here's a stab at a macro (non "super macro") for the example function
>> which won't work because the compiler won't be able to decide on
>> which overload to use:
>>
>> #define DecCheckBit(T, S, W) \
>> inline bool CheckBit(T& mask, uint32 n) \
>> {
>> \
>> Assert((n ge 1) and (n le W), ArgOutOfRangeError, "n")\
>> return ( (mask& (S<< (n-1ui32)) ) != 0); \
>> }
>>
>> DecCheckBit(uint8, 1ui8, 8)
>> DecCheckBit(uint16, 1ui16, 16)
>> DecCheckBit(uint32, 1ui32, 32)
>> DecCheckBit(uint64, 1ui64, 64)
>
> So a macro using non-standard suffixes
While I didn't/don't use the standard suffixes, I see no reason why they
couldn't be used.
> and requiring the type to be
> explicitly specified is superior a template where the type can be
> deduced by the compiler?
Avoid compiler "black magic" is many times beneficial. Think "explicit"
rather than "implicit". In this case, I would say that is clearly so.
>
>> Non-overload versions can be had (in place of the above) with
>> introduction of another macro to generate unique functions instead of
>> overloaded ones:
>>
>> #define CheckBit(T) CheckBit_##T
>>
>> #define DecCheckBit(T, S, W) \
>> inline bool CheckBit(T)(T& mask, uint32 n) \
>> {
>> \
>> Assert((n ge 1) and (n le W), ArgOutOfRangeError, "n")\
>> return ( (mask& (S<< (n-1ui32)) ) != 0); \
>> }
>>
>> The above examples use assertion but that must be changed to an
>> exception, and the suffixes used are not the standard suffixes.
>> Finally, I didn't test the above.
>
> There's a glowing recommendation.
I just wanted to give anyone interested a starting point for further
investigation if they wanted it. I no longer have the dilemma which
prompted me to start this thread.
>
>> Conclusions
>>
>> The C++ template system cannot fully replace preprocessor techniques.
>
> No one said it does. There are a small number of cases where a macro
> is the only solution and few if any where it is a better solution. This
> isn't one of them.
Indeed it is one, to me, that's why I rejected any of the many template
approaches. That there are so many, probably indicates something is
wrong.
>
>> The C++ type system sucks.
>
> How?
Many ways, and this example shows some of them. It's a good question for
you to answer to show that you recognize the C++ shortcomings and are
able to objectively address them.
>
>> The above 2 things make C++ tedious to use and difficult to learn.
>
> Not at all.
Relative to a language that is cohesive in it's mechanisms, the above is
true. Because the tediousness and difficulty is unnecessary, the above is
true. Of course, anyone who puts C++ on a pedestal is apt to call any
assessment of the language that is other than a glowing one, blasphemy.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-08 17:09 -0500
Re: Integer promotions, conversions, coercions and templates :( Ian Collins <ian-news@hotmail.com> - 2011-06-09 10:22 +1200
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-08 17:49 -0500
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-08 19:13 -0500
Re: Integer promotions, conversions, coercions and templates :( Ian Collins <ian-news@hotmail.com> - 2011-06-09 14:32 +1200
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-09 07:30 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-09 06:18 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-09 08:45 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-09 06:51 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-09 13:44 -0500
Re: Integer promotions, conversions, coercions and templates :( Ian Collins <ian-news@hotmail.com> - 2011-06-10 07:37 +1200
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-09 15:11 -0500
Re: Integer promotions, conversions, coercions and templates :( Ian Collins <ian-news@hotmail.com> - 2011-06-10 09:09 +1200
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-09 17:15 -0500
Re: Integer promotions, conversions, coercions and templates :( Ian Collins <ian-news@hotmail.com> - 2011-06-10 10:40 +1200
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 05:07 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-10 03:14 -0700
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-10 03:19 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 06:08 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-10 04:32 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 07:14 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-10 05:27 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 07:35 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-10 06:47 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 06:18 -0500
Re: Integer promotions, conversions, coercions and templates :( Ian Collins <ian-news@hotmail.com> - 2011-06-11 08:08 +1200
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 18:41 -0500
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-10 08:11 -0500
Re: Integer promotions, conversions, coercions and templates :( Öö Tiib <ootiib@hot.ee> - 2011-06-09 06:28 -0700
Re: Integer promotions, conversions, coercions and templates :( "MikeP" <mp011011@some.org> - 2011-06-09 08:50 -0500
Re: Integer promotions, conversions, coercions and templates :( (Summary so far) "MikeP" <mp011011@some.org> - 2011-06-10 08:40 -0500
Re: Integer promotions, conversions, coercions and templates :( (Summary so far) Öö Tiib <ootiib@hot.ee> - 2011-06-10 07:14 -0700
Re: Integer promotions, conversions, coercions and templates :( (Summary so far) "MikeP" <mp011011@some.org> - 2011-06-10 09:17 -0500
Re: Integer promotions, conversions, coercions and templates :( (Summary so far)(Corrections and more) "MikeP" <mp011011@some.org> - 2011-06-10 09:14 -0500
Re: Integer promotions, conversions, coercions and templates :( (Results: Generated Code) "MikeP" <mp011011@some.org> - 2011-06-10 12:43 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-14 18:35 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) Ian Collins <ian-news@hotmail.com> - 2011-06-15 12:51 +1200
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-15 08:45 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-15 03:33 -0700
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-15 09:17 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-16 04:17 -0700
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-16 09:45 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-17 01:56 -0700
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-17 07:58 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-17 06:54 -0700
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-17 09:19 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-17 08:17 -0500
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) Michael DOUBEZ <michael.doubez@free.fr> - 2011-06-17 07:33 -0700
Re: Integer promotions, conversions, coercions and templates :( (Conclusion) "MikeP" <mp011011@some.org> - 2011-06-17 09:49 -0500
csiph-web