Re: [boost] [utility] Proposal to extract some components from Boost.Log

I don’t think you need a “constexpr_if.” You can unconditionally put BOOST_CONSTEXPR in the definition. This will unconditionally add “constexpr” to the member operator (for C++11 systems), which will be ignored if the compiler determines that the attached function (or a particular call) is disqualified from being used in constant expressions. So any extra preprocessor work, or a variant macro, is unnecessary. Sent from Windows Mail From: Andrey Semashev Sent: Sunday, September 01, 2013 4:40 AM To: boost@lists.boost.org On Sunday 01 September 2013 03:27:06 Daryle Walker wrote:
Date: Wed, 28 Aug 2013 12:14:51 +0400 From: andrey.semashev@gmail.com
1. BOOST_EXPLICIT_OPERATOR_BOOL() macro for defining explicit operator bool() for a class.
a. It isn't marked "constexpr." I can add that myself before using "BOOST_EXPLICIT_OPERATOR_BOOL" in "boost/rational.hpp," but what happens if someone corrects it in "explicit_operator_bool.hpp"? Will the (temporary) double definition cause an error?
Well, since there isn't a constexpr_if or something, I don't see a way to add it to BOOST_EXPLICIT_OPERATOR_BOOL. I could add BOOST_EXPLICIT_OPERATOR_BOOL_PP(pre, post), which would add pre() and post() before and after the operator signature. For example:

On Sunday 01 September 2013 11:06:16 Daryle Walker wrote:
I don’t think you need a “constexpr_if.” You can unconditionally put BOOST_CONSTEXPR in the definition. This will unconditionally add “constexpr” to the member operator (for C++11 systems), which will be ignored if the compiler determines that the attached function (or a particular call) is disqualified from being used in constant expressions. So any extra preprocessor work, or a variant macro, is unnecessary.
No, that doesn't work. struct foo { void* m_p; constexpr explicit operator bool () const { return !this->operator!(); } bool operator! () const { return !m_p; } }; g++ -std=gnu++11 constexpr_operator.cpp -o constexpr_operator constexpr_operator.cpp: In member function ‘constexpr foo::operator bool() const’: constexpr_operator.cpp:9:27: error: call to non-constexpr function ‘bool foo::operator!() const’

On 2013-09-01 07:36, Andrey Semashev wrote:
On Sunday 01 September 2013 11:06:16 Daryle Walker wrote:
I don’t think you need a “constexpr_if.” You can unconditionally put BOOST_CONSTEXPR in the definition. This will unconditionally add “constexpr” to the member operator (for C++11 systems), which will be ignored if the compiler determines that the attached function (or a particular call) is disqualified from being used in constant expressions. So any extra preprocessor work, or a variant macro, is unnecessary.
No, that doesn't work.
struct foo { void* m_p;
constexpr explicit operator bool () const { return !this->operator!(); }
bool operator! () const { return !m_p; } };
g++ -std=gnu++11 constexpr_operator.cpp -o constexpr_operator constexpr_operator.cpp: In member function ‘constexpr foo::operator bool() const’: constexpr_operator.cpp:9:27: error: call to non-constexpr function ‘bool foo::operator!() const’
But this works: struct foo { void* m_p; constexpr explicit operator bool () const { return !this->operator!(); } constexpr bool operator! () const { return !m_p; } }; int main() { constexpr auto f = foo{nullptr}; constexpr auto b = bool(f); return b; } John Bytheway

On Sunday 01 September 2013 07:46:40 John Bytheway wrote:
But this works:
struct foo { void* m_p;
constexpr explicit operator bool () const { return !this->operator!(); }
constexpr bool operator! () const { return !m_p; } };
int main() { constexpr auto f = foo{nullptr}; constexpr auto b = bool(f); return b; }
That would force the user to have constexpr operator!, which is not always possible. I think two macros are a better choice.

On Sunday 01 September 2013 15:52:53 you wrote:
On Sunday 01 September 2013 07:46:40 John Bytheway wrote:
But this works:
struct foo {
void* m_p;
constexpr explicit operator bool () const {
return !this->operator!();
}
constexpr bool operator! () const {
return !m_p;
}
};
int main() {
constexpr auto f = foo{nullptr}; constexpr auto b = bool(f); return b;
}
That would force the user to have constexpr operator!, which is not always possible. I think two macros are a better choice.
Extracted the macro. https://svn.boost.org/trac/boost/changeset/85543
participants (3)
-
Andrey Semashev
-
Daryle Walker
-
John Bytheway