|
Boost : |
Subject: Re: [boost] [config] local types as template params
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-01-07 09:42:41
Le 07/01/12 11:23, Lorenzo Caminiti a écrit :
> On Thu, Jan 5, 2012 at 1:00 PM, Mathias Gaunard
> <mathias.gaunard_at_[hidden]> wrote:
>> On 01/02/2012 10:58 AM, Lorenzo Caminiti wrote:
>>> Hello all,
>>>
>>> Is it possible to add a macro
>>> BOOST_CONFIG_LOCAL_TYPES_AS_TEMPLATE_PARAMS to Boost.Config to
>>> indicate if local types can be passed as template parameters?
>>>
>>> 1) Boost.Closure (formerly, Boost.Local) implements some optimizations
>>> when local types can be passed as template parameters.
>>> 2) C++11 always allows to pass local types as template parameters.
>>> 3) Local types cannot be passed as template parameters on C++03
>>> instead but some C++03 compilers MSVC 8 (and older?) allow it anyway.
>>>
>>> // If it is possible to pass local types (classes, etc) as template
>>> parameters.
>>> // This is not possible in pure C++03 but it is possible in some C++03
>>> // extensions (MSVC 8.0) and with C++11 (GCC>= 4.5.x -std=c++0x).
>>> #if (__GNUC__> 4 || (__GNUC__ == 4&& __GNUC_MINOR__> 4))&& \
>>> defined(__GXX_EXPERIMENTAL_CXX0X__)
>>> // From GCC 4.5.x when -std=c++0x specified.
>>> # define BOOST_LOCAL_TYPES_AS_TEMPLATE_PARAMS
>>> #elif defined(_MSC_VER)
>>> // For (all?) MSVC (tested on MVSC 8.0).
>>> # define BOOST_LOCAL_TYPES_AS_TEMPLATE_PARAMS
>>> #endif
>>
>> Boost.Config is not organized like that, it's per compiler.
> I see, I will add the macro to the relative compiler's header.
>
>> the name should also be BOOST_NO_LOCAL_TYPES_AS_TEMPLATE_PARAMS.
> OK (even if the macro will be defined by default on C++03 compilers
> unless tested otherwise-- in other words, it is the most conservative
> to define the macro on C++03).
>
>> Finally this seems incomplete, local types as template params used to work
>> in C++03 with older versions of GCC too.
>> It does indeed work for all versions of MSVC AFAIK.
> Yes, it's incomplete... Can someone with access to many compilers and
> compiler versions try to compile the example below and let me know if
> it compiles? (I only have access to MSVC 8.0 and GCC 4.5.3).
>
> #include<algorithm>
> #include<iostream>
>
> int main() {
> struct s {
> void operator()(int x) {
> std::cout<< x<< std::endl;
> }
> } l;
>
> int nums[] = {1, 2, 3};
> std::for_each(nums, nums + 3, l);
>
> return 0;
> }
>
> Thanks a lot.
> --Lorenzo
>
Lorenzo,
I suggest you to follow the process (see
http://www.boost.org/doc/libs/1_48_0/libs/config/doc/html/boost_config/guidelines_for_boost_authors.html)
to add new macros and propose a patch for the trunk to John.
In this way you will have the results for all the trunk testers.
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk