$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Daryle Walker (darylew_at_[hidden])
Date: 2004-05-05 00:52:35
On 5/2/04 9:38 PM, "Arkadiy Vertleyb" <vertleyb_at_[hidden]> wrote:
> A couple of weeks ago I initiated the discussion about simple typeof
> emulation, and provided an example on how it can be done with the help of
> MPL vector of integral constants.  I then used MS-specific __COUNTER__ macro
> to spare the user from specifying the unique integer for each registered
> class/template.  I hoped to find a way to do something similar in standard
> C++, and asked preprocessor experts for help.
> 
> Indeed, Paul Mensonides suggested such a way.  At first I thought that it
> will not be good enough replacement for the __COUNTER__, but then I realized
> that I was wrong.  So I re-worked my implementation of typeof, and now
> offerring it to your attention.
> 
> Besides removing __COUNTER__, I used the Boost.Preprocessor library to
> cleanup the implementation.  Also, after the discussion with Jody Hagins, I
> put the encoding/decoding classes inside anonimous namespace to avoid
> collisions between translation units.
> 
> The provided example shows what registration needs to be done to calculate
> the type of a lambda functor:
> 
> #include BOOST_TYPEOF_BEGIN_REGISTRATION()
> 
> BOOST_TYPEOF_REGISTER_TEMPLATE(tuples::tuple, 2);
> BOOST_TYPEOF_REGISTER_TEMPLATE(lambda_functor, 1);
> BOOST_TYPEOF_REGISTER_TEMPLATE(lambda_functor_base, 2);
> BOOST_TYPEOF_REGISTER_TEMPLATE(relational_action, 1);
> BOOST_TYPEOF_REGISTER_TEMPLATE(logical_action, 1);
> BOOST_TYPEOF_REGISTER_TYPE(greater_action);
> BOOST_TYPEOF_REGISTER_TYPE(less_action);
> BOOST_TYPEOF_REGISTER_TYPE(and_action);
> BOOST_TYPEOF_REGISTER_TYPE(placeholder<1>);
> BOOST_TYPEOF_REGISTER_TYPE(placeholder<2>);
> 
> #include BOOST_TYPEOF_END_REGISTRATION()
> 
> main()
> {
>   BOOST_TYPEOF_ALLOCATE(fun, _1 > 15 && _2 < 20);  // <unspecified> fun(_1
>> 15 && _2 < 20);
>   int n = 19;
>   assert(fun(n, n));
> }
[TRUNCATE]
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() { /*...*/}
This wouldn't break if the preprocessor counter doesn't reset between files,
but then the same type-of would get lots of Ids.
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com