Boost logo

Boost :

Subject: Re: [boost] [config] local types as template params
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-01-07 05:23:21

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
>> 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.
>> #elif defined(_MSC_VER)
>>     // For (all?) MSVC (tested on MVSC 8.0).
>> #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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at