From fd4885d79122cfd8f66820182cf3e66335dd6847 Mon Sep 17 00:00:00 2001 From: Federico Kircheis Date: Sat, 29 Jun 2019 06:13:47 +0200 Subject: [PATCH] Move enum to private data As it is an implementation detail, and following code compiles, but does not behave as expected: ---- boost::tribool v1 = boost::tribool::false_value; boost::tribool v2 = boost::tribool::true_value; boost::tribool v3 = boost::tribool::indeterminate_value _value; v1 == boost::tribool::false_value; v2 == boost::tribool::true_value; v3 == boost::tribool::indeterminate_value _value; ---- --- include/boost/logic/tribool.hpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/include/boost/logic/tribool.hpp b/include/boost/logic/tribool.hpp index 041c59ce..e1217c52 100644 --- a/include/boost/logic/tribool.hpp +++ b/include/boost/logic/tribool.hpp @@ -71,8 +71,8 @@ indeterminate(tribool x, */ class tribool { -#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) private: +#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) /// INTERNAL ONLY struct dummy { void nonnull() {}; @@ -81,6 +81,12 @@ class tribool typedef void (dummy::*safe_bool)(); #endif + /** + * The actual stored value in this 3-state boolean, which may be false, true, + * or indeterminate. + */ + enum value_t { false_value, true_value, indeterminate_value } value; + public: /** * Construct a new 3-state boolean value with the value 'false'. @@ -126,12 +132,8 @@ class tribool } #endif - - /** - * The actual stored value in this 3-state boolean, which may be false, true, - * or indeterminate. - */ - enum value_t { false_value, true_value, indeterminate_value } value; +friend BOOST_CONSTEXPR inline bool indeterminate(tribool x, detail::indeterminate_t) BOOST_NOEXCEPT; +friend BOOST_CONSTEXPR inline tribool operator!(tribool x) BOOST_NOEXCEPT; }; // Check if the given tribool has an indeterminate value. Also doubles as a @@ -463,7 +465,7 @@ inline bool \ Name(boost::logic::tribool x, \ boost::logic::detail::indeterminate_t = \ boost::logic::detail::indeterminate_t()) \ -{ return x.value == boost::logic::tribool::indeterminate_value; } +{ return boost::logic::indeterminate(x); } #endif // BOOST_LOGIC_TRIBOOL_HPP