[config] local types as template params

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

[config] local types as template params

lcaminiti
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

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?

Thanks.
--Lorenzo

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

Re: [config] local types as template params

alex_perry
lcaminiti wrote
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?
Compiles fine on :-
MSVC 9.0 (VS 2008 - cl version 15.00.221022.08)
MSVC 10.0 (VS 2010 - cl version 16.00.30319.01)

Alex
Reply | Threaded
Open this post in threaded view
|

Re: [config] local types as template params

Mathias Gaunard-2
In reply to this post by lcaminiti
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.
the name should also be BOOST_NO_LOCAL_TYPES_AS_TEMPLATE_PARAMS.

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.


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

Re: [config] local types as template params

lcaminiti
On Thu, Jan 5, 2012 at 1:00 PM, Mathias Gaunard
<[hidden email]> 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

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

Re: [config] local types as template params

Vicente Botet
Le 07/01/12 11:23, Lorenzo Caminiti a écrit :

> On Thu, Jan 5, 2012 at 1:00 PM, Mathias Gaunard
> <[hidden email]>  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


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

Re: [config] local types as template params

Nathan Ridge
In reply to this post by lcaminiti

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

I have access to GCC 4.3 through 4.7.

On GCC 4.3 and 4.4, it does not compile, with or without --std=c++0x
On GCC 4.5, 4.6, and 4.7, it compiles with --std=c++0x, but not without

Presumably it would not compile on older GCC versions either.

Regards,
Nate
     

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

Re: [config] local types as template params

Mathias Gaunard-2
On 01/07/2012 10:29 PM, Nathan Ridge wrote:

> I have access to GCC 4.3 through 4.7.
>
> On GCC 4.3 and 4.4, it does not compile, with or without --std=c++0x
> On GCC 4.5, 4.6, and 4.7, it compiles with --std=c++0x, but not without
>
> Presumably it would not compile on older GCC versions either.

You may want to try with 4.0 or 4.1.
I think they used to allow it.


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

Re: [config] local types as template params

lcaminiti
In reply to this post by Vicente Botet
Vicente Botet wrote
Le 07/01/12 11:23, Lorenzo Caminiti a écrit :
> On Thu, Jan 5, 2012 at 1:00 PM, Mathias Gaunard
> <[hidden email]>  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?
>>>
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.
Sure, I'll follow the process- thanks for the link!

BTW, from that link:

Adding New Defect Macros
When you name the macro, follow the BOOST_NO_SOMETHING naming convention, so that it's obvious that this is a macro reporting a defect.

Adding New Feature Test Macros
When you need to add a macro that describes a feature that the standard does not require, follow the convention for adding a new defect macro (above), but call the macro BOOST_HAS_FOO

Following the case of BOOST_NO_VARIADIC_MACROS, I will name this macro BOOST_NO_LOCAL_TYPES_AS_TEMPLATE_PARAMS and document it under the group of "Macros that describe C++0x features not supported" (because this is a defect macro respect to C++11 but it's a feature macro respect to C++03, I'll name it and document it in respect to C++11).

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

Re: [config] local types as template params

lcaminiti
Vicente Botet wrote
Le 07/01/12 11:23, Lorenzo Caminiti a écrit :
> On Thu, Jan 5, 2012 at 1:00 PM, Mathias Gaunard
> <[hidden email]>  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?
>>>
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)
I'm adding a Boost.Config macro for (I had to shorten the name to fit the < 30 chars file length requirement):

// MACRO:       BOOST_NO_LOCALS_AS_TPARAMS
// TITLE:       local types as template parameters
// DESCRIPTION: If the compiler fails to support local types as template
//              parameters. Local types cannot be used as template parameters
//              in C++03. However, some C++03 compilers and C++11 accept local
//              types as template parameters.

I have a couple of questions.

1) The docs say:
cd into libs/config/test/all and run bjam MACRONAME compiler-list, where MACRONAME is the name of the new macro, and compiler-list is a space separated list of compilers to test with.

What compiler-list shall I specify? On my machine I only have MSVC 8 and GCC 4.5.3... should this be:

bjam BOOST_NO_LOCALS_AS_TPARAMS msvc gcc

(This doesn't work...)

2) The docs say:
Then you should:
Define the defect macro in those config headers that require it.

How do I know which config herders require the macro? I'd expect to add the boost_no_locals_as_tparams.ipp and related .cpp to Boost.Config test suite, commit to trunk, look at the trunk regression test results (http://www.boost.org/development/tests/trunk/developer/config.html) and from these results determine which compiler and therefore which Boost.Config header needs the BOOST_NO_LOCALS_AS_TPARAMS definition... However, I don't think that's the process (so I have committed nothing to Boost.Config in trunk yet).

For example, how would I know if to add the macro to boost/config/borland.hpp given that I don't have a Borland compiler to run the BOOST_NO_LOCALS_AS_TPARAMS' test myself?

Thanks a lot.
--Lorenzo
Reply | Threaded
Open this post in threaded view
|

Re: [config] local types as template params

John Maddock-3
> I'm adding a Boost.Config macro for (I had to shorten the name to fit the
> <
> 30 chars file length requirement):

Even if the test file name has to be shortened, I'd still use
BOOST_NO_LOCAL_TYPES_AS_TEMPLATE_PARAMS for the macro name.

> 1) The docs say:
> cd into libs/config/test/all and run bjam MACRONAME compiler-list, where
> MACRONAME is the name of the new macro, and compiler-list is a space
> separated list of compilers to test with.
>
> What compiler-list shall I specify? On my machine I only have MSVC 8 and
> GCC
> 4.5.3... should this be:
>
> bjam BOOST_NO_LOCALS_AS_TPARAMS msvc gcc
>
> (This doesn't work...)

Are they configured in your user-config.jam?  It should work for sure.  Also
don't forget to test C++0x mode with gcc:

bjam -a gcc cxxflags=-std=c++0x

> 2) The docs say:
> Then you should:
> Define the defect macro in those config headers that require it.
>
> How do I know which config herders require the macro? I'd expect to add
> the
> boost_no_locals_as_tparams.ipp and related .cpp to Boost.Config test
> suite,
> commit to trunk, look at the trunk regression test results
> (http://www.boost.org/development/tests/trunk/developer/config.html) and
> from these results determine which compiler and therefore which
> Boost.Config
> header needs the BOOST_NO_LOCALS_AS_TPARAMS definition... However, I don't
> think that's the process (so I have committed nothing to Boost.Config in
> trunk yet).
>
> For example, how would I know if to add the macro to
> boost/config/borland.hpp given that I don't have a Borland compiler to run
> the BOOST_NO_LOCALS_AS_TPARAMS' test myself?

For sure there will be compilers you can't test locally, the aim though is
to get folks to test as much as they can locally so Boost.Config
a) Doesn't change often
b) Is broken for as short a time as possible (if at all).

If in doubt, ping me with a diff of what you're about to commit before you
do.

HTH, John.


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

Re: [config] local types as template params

lcaminiti
John Maddock-3 wrote
> I'm adding a Boost.Config macro for (I had to shorten the name to fit the
> ...
For sure there will be compilers you can't test locally, the aim though is
to get folks to test as much as they can locally so Boost.Config
a) Doesn't change often
b) Is broken for as short a time as possible (if at all).

If in doubt, ping me with a diff of what you're about to commit before you
do.
I have just committed BOOST_NO_LOCAL_CLASS_TEMPLATE_PARAMETERS to Boost.Config in trunk r77457 following the steps from:
http://www.boost.org/doc/libs/1_49_0/libs/config/doc/html/boost_config/guidelines_for_boost_authors.html#boost_config.guidelines_for_boost_authors.adding_new_defect_macros

I'll be monitoring the trunk tests. Please let me know if I have done anything wrong ;) -- it's my first commit to Boost.Config.

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

Re: [config] local types as template params

Michel MORIN
lcaminiti wrote:
> I have just committed BOOST_NO_LOCAL_CLASS_TEMPLATE_PARAMETERS to
> Boost.Config in trunk r77457

Shouldn't we name BOOST_NO_LOCAL_CLASS_TEMPLATE_ARGS?
(N2657 says "Local and Unnamed Types as Template Arguments.")

Regards,
Michel

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

Re: [config] local types as template params

lcaminiti
Michel MORIN wrote
lcaminiti wrote:
> I have just committed BOOST_NO_LOCAL_CLASS_TEMPLATE_PARAMETERS to
> Boost.Config in trunk r77457

Shouldn't we name BOOST_NO_LOCAL_CLASS_TEMPLATE_ARGS?
(N2657 says "Local and Unnamed Types as Template Arguments.")
I considered that as well as having the "AS" in the middle of the name. However, at the end I chose the name to be consistent with the existing:

BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS

Thanks.
--Lorenzo