Boost logo

Boost :

Subject: [boost] [config] local types as template params
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-01-02 04:58:53

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)) && \
    // From GCC 4.5.x when -std=c++0x specified.
#elif defined(_MSC_VER)
    // For (all?) MSVC (tested on MVSC 8.0).

All, can you please try to compile the following example on different
compilers/versions and let me know the outcome? If this example
compiles successfully then the specific compiler supports local types
as template parameters:

#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;

For example, this compiles on GCC >= 4.5.x w/ C++0x extensions enabled
and on MSVC 8.0- does it compile on all MSVC versions?


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