Re: Template specialization to get just-wide-enough integer

From: Simon Trew (noneofyour_at_business.guv)
Date: 10/29/04


Date: Fri, 29 Oct 2004 10:45:47 +0100


> template < typename TL, size_t MINSIZE, typename ERROR_T = TypeError >
> struct find_if_at_least
> {
> typedef typename
> TypeIF
> < (sizeof(typename TL::first_type)>=MINSIZE),
> typename TL::first_type,
> typename find_if_at_least< typename TL::tail_type, MINSIZE,
> ERROR_T>::type
> >::type
> type;
> };
>

But then I have to specify my size in bytes (chars) rather than bits, right?
Because you're using sizeof. I guess I could just do sizeof(typename
TL::first_type)*8 >=MINSIZE), right? (I will assume 8 bits to the byte).

I like that you don't actually have to know the sizes of the integer types
to do the specializations for them.



Relevant Pages

  • Re: C90 penetration
    ... and just specify that the "precision" ... A bit-field whose size is CHAR_BIT, can certainly be represented by a char; bit fields of a larger size clearly cannot be represented as a single char. ... Also, the standard requires that if a bit field with a width of 3 is followed by a bit field with a width of 4, then if there's enough room in the allocation unit, they must be allocated in adjacent bits within that allocation unit; that's pretty hard to do if you implement them as chars. ...
    (comp.lang.c)
  • Re: Size-specific memory access words
    ... for characters ... but I don't believe there is anything in ANS to ... > specify that C@ and C! ... > just the same as CHARS doesn't have to be a NOP. ...
    (comp.lang.forth)
  • Re: Using sprintf_s in VC++ 6.0
    ... But that's precisely what sizeof does. ... and it would be wrong for the StringCbXXX functions ... It needs to be done in this context; alternatively, you can specify the ... characters) vs. number of bytes is precisely why I like the StrSafe library. ...
    (microsoft.public.vc.mfc)
  • Re: bytes calculation
    ... Please, are you a lawyer? ... sizeof returns the number of chars in an object ... Nick Keighley ...
    (comp.lang.c)
  • Re: array questions
    ... >>> an object of 10 chars. ... >>> Why is this anomalous behaviour? ... > A lot of people forget that sizeof is not a function call, ... Prev by Date: ...
    (comp.lang.c)