Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-12-03 16:59:32


Hi all,

Attached is some non-conforming code which automatically assigns a unique
integer id to an arbitrary type. It's based on this post by Daniel Wallin:

    http://lists.boost.org/MailArchives/boost/msg69842.php

Example:

    #include <boost/static_assert.hpp>
    #include <boost/unique_id.hpp>

    int main()
    {
        BOOST_STATIC_ASSERT(BOOST_UNIQUE_ID(void) == 0);
        BOOST_STATIC_ASSERT(BOOST_UNIQUE_ID(bool) == 1);
        BOOST_STATIC_ASSERT(BOOST_UNIQUE_ID(char) == 2);
        BOOST_STATIC_ASSERT(BOOST_UNIQUE_ID(void) == 0);
        BOOST_STATIC_ASSERT(BOOST_UNIQUE_ID(bool) == 1);
        BOOST_STATIC_ASSERT(BOOST_UNIQUE_ID(char) == 2);
    }

Obviously the ids assigned will be different depending on the order in which
types are passed to BOOST_UNIQUE_ID.

It's a novelty not just because it's non-conforming but also because after
assigning ids to about fifty types it slows down to a deadly crawl, and maxes
out at about 110 types (on VC7.1, using over 300MB RAM). I tried several forms
of loop unrolling, and they don't help much.

I'm posting this now because yesterday I figured out how to make it work on EDG
(except for Comeau). It now works on VC7.1, VC8.0 (beta), GCC 3.2 (MinGW), GCC
3.4.1 (Cygwin), Intel 7.0 and 8.0 for Windows (in strict mode), and on the
preview of the Borland EDG-based compiler I downloaded about half a year ago.

I still need conforming-compiler workarounds for Comeau and Metrowerks. ;-)

Best Regards,
Jonathan

begin 666 unique_id.zip
M4$L#! H``````'%R_at_S$````````````````/````;&EB<R]U;FEQ=65?:60O
M4$L#!!0````(`!AP_at_S&5>-46[ ```+(&```7````;&EB<R]U;FEQ=65?:60O
M=&5S="YC<'#MTT]/PC 8!O![DWZ')ERV"SB4?T%,4#GL`M&-<U/6RIJ4%M?6
MB_&[.SM%PHEW5^AQW2_/F_1Y.U(7RG-![C?&6->SCCE94&:MJ%RWW.\?,.J<
M_..U?/>"2OY[CY'4CNR8U%&,T2=&I#Z/JU66TRR?Y^D3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NSR!H;J$_&S:K
MT4W9CKAN<:8Z)S MKCZ<)C+<P.NQZ'VKN3^.'-F:3&U:-+,&A%M<()Q9EXK7
M8B\0L,7V1(27L'A.R'/KQ8289DUI?7':IJ>.G4S_=],;06)1IFJ@\OZK")H6
M[]7>QW(X*T3/E.R X$;LZ:O5*M!$&T]VN'<\2?@IK;!+:^ZWSLZEZWFI=PE)
MN-0/S?CJ<!KU4:">">()'VS[]MCBF.*1GGR$#FI>AJ:S0^<AG.B:]7M6.ZIZ
M98QZ&))($\E1##9+$Z23_at_UD-^*S+FQ&ADNT$&WXA3UI;-?=7AE5#W79U#[NQ
MGS_#<]Z>%J@]MK/%M4Y,WQZF,JF]U1[__at_IX#5SH#XRHO3I.!<_G+7?,BG71J
M%YT1I7K<O= _-KC:Y \,D*C&DZ(>6NH)5&?%$P.Y;!:]OOH'4$L#! H`````
M`)ER_at_S$````````````````&````8F]O<W0O4$L!`A0`"@``````<7*#,0``
M``````````````\````````````0`````````&QI8G,O=6YI<75E7VED+U!+
M`0(4`!0````(`!AP_at_S&5>-46[ ```+(&```7``````````$`( ```"T```!L
M:6)S+W5N:7%U95]I9"]T97-T+F-P<%!+`0(4``H``````)QR_at_S$`````````
M```````%````````````$ ```$X!``!L:6)S+U!+`0(4`!0````(`$-O_at_S'*
MX)&D;@,``*,+```3``````````$`( ```'$!``!B;V]S="]U;FEQ=65?:60N
M:'!P4$L!`A0`"@``````F7*#,0````````````````8````````````0````
@$ 4``&)O;W-T+U!+!08`````!0`%`"H!```T!0``````
`
end


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk