Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-05-05 11:26:14


"Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:

> "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.

I'm afraid it doesn't, technically, if typeof is used within a
template that's seen in multiple translation units. That said, I'm
willing to accept it if it really works.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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