Support constexpr boost::none with recent Boost versions.

This commit is contained in:
Vladimir Lichevsky 2021-02-10 20:45:41 +03:00 committed by The Phantom Derpstorm
parent b77f1a2102
commit 810c96b97b
4 changed files with 36 additions and 12 deletions

View File

@ -29,6 +29,14 @@
#include <sol/traits.hpp> #include <sol/traits.hpp>
#if SOL_IS_ON(SOL_USE_BOOST_I_) #if SOL_IS_ON(SOL_USE_BOOST_I_)
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 107500 // Since Boost 1.75.0 boost::none is constexpr
#define COULD_BE_CONSTEXPR constexpr
#else
#define COULD_BE_CONSTEXPR const
#endif // BOOST_VERSION
#else #else
#include <sol/optional_implementation.hpp> #include <sol/optional_implementation.hpp>
#endif // Boost vs. Better optional #endif // Boost vs. Better optional
@ -41,7 +49,7 @@ namespace sol {
template <typename T> template <typename T>
using optional = boost::optional<T>; using optional = boost::optional<T>;
using nullopt_t = boost::none_t; using nullopt_t = boost::none_t;
const nullopt_t nullopt = boost::none; COULD_BE_CONSTEXPR nullopt_t nullopt = boost::none;
#endif // Boost vs. Better optional #endif // Boost vs. Better optional
namespace meta { namespace meta {
@ -61,13 +69,13 @@ namespace sol {
#if SOL_IS_ON(SOL_USE_BOOST_I_) #if SOL_IS_ON(SOL_USE_BOOST_I_)
template <typename T> template <typename T>
struct associated_nullopt<boost::optional<T>> { struct associated_nullopt<boost::optional<T>> {
inline static const boost::none_t value = boost::none; inline static COULD_BE_CONSTEXPR boost::none_t value = boost::none;
}; };
#endif // Boost nullopt #endif // Boost nullopt
#if SOL_IS_ON(SOL_USE_BOOST_I_) #if SOL_IS_ON(SOL_USE_BOOST_I_)
template <typename T> template <typename T>
inline const auto associated_nullopt_v = associated_nullopt<T>::value; inline COULD_BE_CONSTEXPR auto associated_nullopt_v = associated_nullopt<T>::value;
#else #else
template <typename T> template <typename T>
inline constexpr auto associated_nullopt_v = associated_nullopt<T>::value; inline constexpr auto associated_nullopt_v = associated_nullopt<T>::value;
@ -75,4 +83,8 @@ namespace sol {
} // namespace detail } // namespace detail
} // namespace sol } // namespace sol
#if SOL_IS_ON(SOL_USE_BOOST_I_)
#undef COULD_BE_CONSTEXPR
#endif
#endif // SOL_OPTIONAL_HPP #endif // SOL_OPTIONAL_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2021-02-03 01:36:37.733271 UTC // Generated 2021-02-10 17:29:50.720589 UTC
// This header was generated with sol v3.2.3 (revision 22ecd349) // This header was generated with sol v3.2.3 (revision b77f1a21)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_CONFIG_HPP #ifndef SOL_SINGLE_CONFIG_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2021-02-03 01:36:37.666578 UTC // Generated 2021-02-10 17:29:50.717841 UTC
// This header was generated with sol v3.2.3 (revision 22ecd349) // This header was generated with sol v3.2.3 (revision b77f1a21)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2021-02-03 01:36:36.756148 UTC // Generated 2021-02-10 17:29:50.610143 UTC
// This header was generated with sol v3.2.3 (revision 22ecd349) // This header was generated with sol v3.2.3 (revision b77f1a21)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -4131,6 +4131,14 @@ namespace sol {
#if SOL_IS_ON(SOL_USE_BOOST_I_) #if SOL_IS_ON(SOL_USE_BOOST_I_)
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 107500 // Since Boost 1.75.0 boost::none is constexpr
#define COULD_BE_CONSTEXPR constexpr
#else
#define COULD_BE_CONSTEXPR const
#endif // BOOST_VERSION
#else #else
// beginning of sol/optional_implementation.hpp // beginning of sol/optional_implementation.hpp
@ -6373,7 +6381,7 @@ namespace sol {
template <typename T> template <typename T>
using optional = boost::optional<T>; using optional = boost::optional<T>;
using nullopt_t = boost::none_t; using nullopt_t = boost::none_t;
const nullopt_t nullopt = boost::none; COULD_BE_CONSTEXPR nullopt_t nullopt = boost::none;
#endif // Boost vs. Better optional #endif // Boost vs. Better optional
namespace meta { namespace meta {
@ -6393,13 +6401,13 @@ namespace sol {
#if SOL_IS_ON(SOL_USE_BOOST_I_) #if SOL_IS_ON(SOL_USE_BOOST_I_)
template <typename T> template <typename T>
struct associated_nullopt<boost::optional<T>> { struct associated_nullopt<boost::optional<T>> {
inline static const boost::none_t value = boost::none; inline static COULD_BE_CONSTEXPR boost::none_t value = boost::none;
}; };
#endif // Boost nullopt #endif // Boost nullopt
#if SOL_IS_ON(SOL_USE_BOOST_I_) #if SOL_IS_ON(SOL_USE_BOOST_I_)
template <typename T> template <typename T>
inline const auto associated_nullopt_v = associated_nullopt<T>::value; inline COULD_BE_CONSTEXPR auto associated_nullopt_v = associated_nullopt<T>::value;
#else #else
template <typename T> template <typename T>
inline constexpr auto associated_nullopt_v = associated_nullopt<T>::value; inline constexpr auto associated_nullopt_v = associated_nullopt<T>::value;
@ -6407,6 +6415,10 @@ namespace sol {
} // namespace detail } // namespace detail
} // namespace sol } // namespace sol
#if SOL_IS_ON(SOL_USE_BOOST_I_)
#undef COULD_BE_CONSTEXPR
#endif
// end of sol/optional.hpp // end of sol/optional.hpp
// beginning of sol/raii.hpp // beginning of sol/raii.hpp