[config] BOOST_STATIC_CONSTEXPR in C++11 vs C++14
This conversation is in reference to
https://github.com/boostorg/math/pull/82 but I'm posting it here
because it might be of interest to some.
On 22 August 2017 at 13:53, jzmaddock
Note that those changes don't actually make the functions constexpr - or indeed change the way the constants are initialized - in fact in C++14 BOOST_STATIC_CONSTEXPR doesn't even imply the constants are "const (C++11 is different, and early implementations prevent you from writing "constexpr const" which is what C++14 permits).
Since BOOST_STATIC_CONSTEXPR behaves differently in C++11 and 14, would it be a good idea for boost.config to provide a macro for handling the `static const var = ...;` kind of variable initializations in a portable manner? Maybe something like BOOST_COMPILETIME_CONSTANT? Such a macro might will be useful for declarations where we want the variable to be a constant in all possible senses (compile-time, run-time) and allow generating the most optimal code possible with the language version, compiler being used in a portable manner. An example of the kind of constants I am talking about can be seen here: https://github.com/boostorg/math/blob/develop/include/boost/math/special_fun... Lakshay
This seems like a reasonable idea.
On Tue, Aug 22, 2017 at 5:28 AM, Lakshay Garg via Boost
This conversation is in reference to https://github.com/boostorg/math/pull/82 but I'm posting it here because it might be of interest to some.
On 22 August 2017 at 13:53, jzmaddock
wrote: Note that those changes don't actually make the functions constexpr - or indeed change the way the constants are initialized - in fact in C++14 BOOST_STATIC_CONSTEXPR doesn't even imply the constants are "const (C++11 is different, and early implementations prevent you from writing "constexpr const" which is what C++14 permits).
Since BOOST_STATIC_CONSTEXPR behaves differently in C++11 and 14, would it be a good idea for boost.config to provide a macro for handling the `static const var = ...;` kind of variable initializations in a portable manner? Maybe something like BOOST_COMPILETIME_CONSTANT?
Such a macro might will be useful for declarations where we want the variable to be a constant in all possible senses (compile-time, run-time) and allow generating the most optimal code possible with the language version, compiler being used in a portable manner.
An example of the kind of constants I am talking about can be seen here: https://github.com/boostorg/math/blob/develop/include/boost/math/special_fun...
Lakshay
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On 22 August 2017 at 20:12, Gary Furnish via Boost
On Tue, Aug 22, 2017 at 5:28 AM, Lakshay Garg via Boost
wrote: This conversation is in reference to https://github.com/boostorg/math/pull/82 but I'm posting it here because it might be of interest to some.
On 22 August 2017 at 13:53, jzmaddock
wrote: Note that those changes don't actually make the functions constexpr - or indeed change the way the constants are initialized - in fact in C++14 BOOST_STATIC_CONSTEXPR doesn't even imply the constants are "const (C++11 is different, and early implementations prevent you from writing "constexpr const" which is what C++14 permits).
Since BOOST_STATIC_CONSTEXPR behaves differently in C++11 and 14, would it be a good idea for boost.config to provide a macro for handling the `static const var = ...;` kind of variable initializations in a portable manner? Maybe something like BOOST_COMPILETIME_CONSTANT?
Such a macro might will be useful for declarations where we want the variable to be a constant in all possible senses (compile-time, run-time) and allow generating the most optimal code possible with the language version, compiler being used in a portable manner.
An example of the kind of constants I am talking about can be seen here: https://github.com/boostorg/math/blob/develop/include/boost/math/special_fun...
Lakshay
This seems like a reasonable idea.
Since I am just getting started with boost, I don't have much idea on how to go about doing this. It would be very helpful is people can post in their suggestions/reference material so I can look at it and write such a macro. Lakshay
I'd take a look at making something like BOOST_CONSTEXPR_AND_CONST
similarly to BOOST_CONSTEXPR_OR_CONST using BOOST_CXX14_CONSTEXPR.
See http://www.boost.org/doc/libs/1_65_0/libs/config/doc/html/boost_config/boost...
But I'd name it something like BOOST_COMPILETIME_CONSTANT because
BOOST_CONSTEXPR_AND_CONST would seem to imply always constexpr and
const, which is not what you want. Really though you want to get
other people who are more knowledgeable then I am involved if you want
to add a cross-library macro, so maybe make one for your use case to
test it.
On Tue, Aug 22, 2017 at 9:44 AM, Lakshay Garg
On 22 August 2017 at 20:12, Gary Furnish via Boost
wrote: On Tue, Aug 22, 2017 at 5:28 AM, Lakshay Garg via Boost
wrote: This conversation is in reference to https://github.com/boostorg/math/pull/82 but I'm posting it here because it might be of interest to some.
On 22 August 2017 at 13:53, jzmaddock
wrote: Note that those changes don't actually make the functions constexpr - or indeed change the way the constants are initialized - in fact in C++14 BOOST_STATIC_CONSTEXPR doesn't even imply the constants are "const (C++11 is different, and early implementations prevent you from writing "constexpr const" which is what C++14 permits).
Since BOOST_STATIC_CONSTEXPR behaves differently in C++11 and 14, would it be a good idea for boost.config to provide a macro for handling the `static const var = ...;` kind of variable initializations in a portable manner? Maybe something like BOOST_COMPILETIME_CONSTANT?
Such a macro might will be useful for declarations where we want the variable to be a constant in all possible senses (compile-time, run-time) and allow generating the most optimal code possible with the language version, compiler being used in a portable manner.
An example of the kind of constants I am talking about can be seen here: https://github.com/boostorg/math/blob/develop/include/boost/math/special_fun...
Lakshay
This seems like a reasonable idea.
Since I am just getting started with boost, I don't have much idea on how to go about doing this. It would be very helpful is people can post in their suggestions/reference material so I can look at it and write such a macro.
Lakshay
On 08/22/17 19:18, Gary Furnish via Boost wrote:
I'd take a look at making something like BOOST_CONSTEXPR_AND_CONST similarly to BOOST_CONSTEXPR_OR_CONST using BOOST_CXX14_CONSTEXPR. See http://www.boost.org/doc/libs/1_65_0/libs/config/doc/html/boost_config/boost... But I'd name it something like BOOST_COMPILETIME_CONSTANT because BOOST_CONSTEXPR_AND_CONST would seem to imply always constexpr and const, which is not what you want. Really though you want to get other people who are more knowledgeable then I am involved if you want to add a cross-library macro, so maybe make one for your use case to test it.
Gary, please, don't top post. http://www.boost.org/community/policy.html#quoting
On Tue, Aug 22, 2017 at 9:44 AM, Lakshay Garg
wrote: On 22 August 2017 at 20:12, Gary Furnish via Boost
wrote: On Tue, Aug 22, 2017 at 5:28 AM, Lakshay Garg via Boost
wrote: This conversation is in reference to https://github.com/boostorg/math/pull/82 but I'm posting it here because it might be of interest to some.
On 22 August 2017 at 13:53, jzmaddock
wrote: Note that those changes don't actually make the functions constexpr - or indeed change the way the constants are initialized - in fact in C++14 BOOST_STATIC_CONSTEXPR doesn't even imply the constants are "const (C++11 is different, and early implementations prevent you from writing "constexpr const" which is what C++14 permits).
Since BOOST_STATIC_CONSTEXPR behaves differently in C++11 and 14, would it be a good idea for boost.config to provide a macro for handling the `static const var = ...;` kind of variable initializations in a portable manner? Maybe something like BOOST_COMPILETIME_CONSTANT?
Such a macro might will be useful for declarations where we want the variable to be a constant in all possible senses (compile-time, run-time) and allow generating the most optimal code possible with the language version, compiler being used in a portable manner.
An example of the kind of constants I am talking about can be seen here: https://github.com/boostorg/math/blob/develop/include/boost/math/special_fun...
Lakshay
This seems like a reasonable idea.
Since I am just getting started with boost, I don't have much idea on how to go about doing this. It would be very helpful is people can post in their suggestions/reference material so I can look at it and write such a macro.
On 22/08/2017 17:18, Gary Furnish via Boost wrote:
I'd take a look at making something like BOOST_CONSTEXPR_AND_CONST similarly to BOOST_CONSTEXPR_OR_CONST using BOOST_CXX14_CONSTEXPR. See http://www.boost.org/doc/libs/1_65_0/libs/config/doc/html/boost_config/boost... But I'd name it something like BOOST_COMPILETIME_CONSTANT because BOOST_CONSTEXPR_AND_CONST would seem to imply always constexpr and const, which is not what you want. Really though you want to get other people who are more knowledgeable then I am involved if you want to add a cross-library macro, so maybe make one for your use case to test it.
Actually I think it's a lot simpler than this: when it was added, |BOOST_CONSTEXPR_OR_CONST did what it says, and what it's documented to do - namely declare something const or constexpr (which implied const at the time). Subsequently it's been broken by C++14 where constexpr no longer implies const. It just needs updating is all, and fixing that will automatically fix ||BOOST_STATIC_CONSTEXPR as well. See https://github.com/boostorg/config/pull/182.| --- This email has been checked for viruses by AVG. http://www.avg.com
On 22 August 2017 at 23:33, John Maddock via Boost
On 22/08/2017 17:18, Gary Furnish via Boost wrote:
I'd take a look at making something like BOOST_CONSTEXPR_AND_CONST similarly to BOOST_CONSTEXPR_OR_CONST using BOOST_CXX14_CONSTEXPR. See http://www.boost.org/doc/libs/1_65_0/libs/config/doc/html/boost_config/boost... But I'd name it something like BOOST_COMPILETIME_CONSTANT because BOOST_CONSTEXPR_AND_CONST would seem to imply always constexpr and const, which is not what you want. Really though you want to get other people who are more knowledgeable then I am involved if you want to add a cross-library macro, so maybe make one for your use case to test it.
Actually I think it's a lot simpler than this: when it was added, |BOOST_CONSTEXPR_OR_CONST did what it says, and what it's documented to do - namely declare something const or constexpr (which implied const at the time). Subsequently it's been broken by C++14 where constexpr no longer implies const. It just needs updating is all, and fixing that will
But if we continue to call it BOOST_CONSTEXPR_OR_CONST, it would mean something that is not compliant with the C++14 standard. Shouldn't we have another macro, very similar to BOOST_CONSTEXPR_OR_CONST, just handling the case for C++14 in a different manner. Lakshay
Actually I think it's a lot simpler than this: when it was added, |BOOST_CONSTEXPR_OR_CONST did what it says, and what it's documented to do - namely declare something const or constexpr (which implied const at
John Maddock wrote: the time). Subsequently it's been broken by C++14 where constexpr no longer implies const. I don't think that this is true; constexpr does imply const in C++14 for variables. It no longer implies const for member functions, but that's a separate matter.
On 22/08/2017 19:40, Peter Dimov via Boost wrote:
John Maddock wrote:
Actually I think it's a lot simpler than this: when it was added, |BOOST_CONSTEXPR_OR_CONST did what it says, and what it's documented to do - namely declare something const or constexpr (which implied const at the time). Subsequently it's been broken by C++14 where constexpr no longer implies const.
I don't think that this is true; constexpr does imply const in C++14 for variables. It no longer implies const for member functions, but that's a separate matter.
Ah, I think you're correct - I'd obviously misremembered this - apologies for the noise, we can just forget the whole thing! John. --- This email has been checked for viruses by AVG. http://www.avg.com
participants (5)
-
Andrey Semashev
-
Gary Furnish
-
John Maddock
-
Lakshay Garg
-
Peter Dimov