Boost logo

Boost :

From: Bronek Kozicki (brok_at_[hidden])
Date: 2006-07-04 18:10:30


Peter Dimov wrote:
> I suspect there is something I'm missing. Let's use examples:
>
> // file1
>
> struct tag1;
> set<tag1>();
>
> // file2
>
> struct tagl;
> get<tagl>(); // NULL
>
> How can the compiler know that you misspelled tag1 as tagl? It can't.

Indeed, but you can put tag1 in a separate header file and then include it.
Had you used name nested into namespace (or type) that solution would be more
obvious. To force it I even proposed to require complete type, but I do not
insist that it's better (it's just different). The point of using tag is that
compiler CAN help you to guarantee name uniqueness and provide name check.
Compiler will not help you if you do not ask for it (like in your example).
But at least you CAN use it, it will provide benefits and will NOT force you
to use centralized location for all tags or build complex infrastructure -
simple C++ design with nested names will suffice.

If you use string, compiler will NOT help at all - no name check and no
uniqueness warranties, unless you have single centralized location to store
all strings and/or build complex infrastructure to manage their uniqueness.

B.


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