[config] Local classes as template parameters

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[config] Local classes as template parameters

lcaminiti
On Sat, Feb 12, 2011 at 5:50 AM, John Bytheway
<[hidden email]> wrote:

> On 11/02/11 22:29, Lorenzo Caminiti wrote:
>> On Fri, Feb 11, 2011 at 4:31 PM, Lorenzo Caminiti <[hidden email]> wrote:
>>> From: John Bytheway <[hidden email]>
>>> 2. Might anyone care so much about performance that they absolutely must
>>> have the code inlined?  The answer is probably "yes" (or at least there
>>> will be people who *think* they care, which is also a problem).  For
>>> these people you could, if you choose, provide an alternate
>>> implementation which doesn't indirect through local::function<>, and
>>> thus will only work in C++0x (or C++03 with non-standard extensions).
>>
>> Without inheriting from local::function_base<> and then using
>> local::function_ref<> the local struct cannot be passed as a template
>> parameter in C++. Is this different for C++0x (C++03)?
>
> Yes, in C++0x local structs can be passed as template parameters.
> Obviously, in C++0x there are lambdas too, so you might think your
> library is useless, but I'd expect most compilers to support passing
> local structs as template parameters before they support lambdas, so
> there is some advantage in having this intermediate implementation.
> Also, your macros would allow writing code that worked in C++0x and
> C++03, with the virtual function business in only those compilers/modes
> where it is necessary.

Hello all,

Is there a Boost.Config macro that indicates if the compiler allows
local classes to be passed as template parameters?

Thank you.

--
Lorenzo
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [config] Local classes as template parameters

lcaminiti
lcaminiti wrote
Is there a Boost.Config macro that indicates if the compiler allows
local classes to be passed as template parameters?
Does anyone know if there is such a macro in Boost.Config?

For example, this config macro will tell if the following is allowed or not (supported by C++03 and later standards):

int main() {
    struct { // Local class.
        void operator()(double x) { std::cout << x << std::endl; }
    } print;

    std::vector<double> v(3);
    v[0] = 1.1; v[1] = 2.2; v[2] = 3.3;

    // The config macro will tell if compiler supports passing local object `print` as template param or not.
    std::for_each(v.begin(), v.end(), print);

    return 0;
}

Thanks a lot.

--Lorenzo
Reply | Threaded
Open this post in threaded view
|

Re: [config] Local classes as template parameters

John Maddock-3
>> Is there a Boost.Config macro that indicates if the compiler allows
>> local classes to be passed as template parameters?
>>
>
> Does anyone know if there is such a macro in Boost.Config?

I don't believe so, but note that we don't add new macros unless there is a
clear need in a Boost library.

HTH, John.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost