Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-05-05 08:37:11


"Daryle Walker" <darylew_at_[hidden]> wrote

> Wouldn't the program need exactly one master type-of list? Since C and
C++
> don't have cross-module consolidation, just text dumps of common files
that
> work by "coincidence", couldn't you break ODR by:
>
> File1.cpp:
> #include BOOST_TYPEOF_BEGIN_REGISTRATION()
> BOOST_TYPEOF_REGISTER_TYPE(greater_action); //1
> BOOST_TYPEOF_REGISTER_TYPE(less_action); //2
> BOOST_TYPEOF_REGISTER_TYPE(and_action); //3
> #include BOOST_TYPEOF_END_REGISTRATION()
> int my_func1() { /*...*/}
>
> File2.cpp:
> #include BOOST_TYPEOF_BEGIN_REGISTRATION()
> BOOST_TYPEOF_REGISTER_TYPE(placeholder<1>); //1
> BOOST_TYPEOF_REGISTER_TYPE(less_action); //2 (only one the same)
> BOOST_TYPEOF_REGISTER_TYPE(greater_action); //3
> #include BOOST_TYPEOF_END_REGISTRATION()
> int my_func2() { /*...*/}

I could, but I use anonimous namespaces to avoid this. This ensures every
compilation unit has it's own set of encoding/decoding classes, and takes
care of ODR.

> This wouldn't break if the preprocessor counter doesn't reset between
files,
> but then the same type-of would get lots of Ids.

The same type may be encoded/decoded using different set of integral
constants in different compilation units. I don't see a problem here since
encoding/decoding always happens inside the same compile-time expression,
and therefore inside the same translation unit.

Regards,
Arkadiy


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