mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Livnig dangerously and not running the tests, just shooting from the hip.
One day I'll get this all right...
This commit is contained in:
parent
6017f63857
commit
26cbadc5b2
@ -1396,14 +1396,14 @@ namespace sol {
|
||||
/// \returns the stored value if there is one, otherwise returns `u`
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
constexpr T& value_or(U&& u) const& {
|
||||
constexpr T value_or(U&& u) const& {
|
||||
static_assert(std::is_copy_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be copy constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
SOL_TL_OPTIONAL_11_CONSTEXPR T& value_or(U&& u) && {
|
||||
SOL_TL_OPTIONAL_11_CONSTEXPR T value_or(U&& u) && {
|
||||
static_assert(std::is_move_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be move constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
@ -2240,16 +2240,9 @@ namespace sol {
|
||||
/// \returns the stored value if there is one, otherwise returns `u`
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
constexpr T& value_or(U&& u) const& {
|
||||
static_assert(std::is_copy_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be copy constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
SOL_TL_OPTIONAL_11_CONSTEXPR T& value_or(U&& u) && {
|
||||
static_assert(std::is_move_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be move constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
constexpr T& value_or(U&& u) const {
|
||||
static_assert(std::is_convertible<U&&, T&>::value, "T must be convertible from U");
|
||||
return has_value() ? const_cast<T&>(**this) : static_cast<T&>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
/// Destroys the stored value if one exists, making the optional empty
|
||||
|
@ -20,8 +20,8 @@
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2019-03-29 03:22:11.311923 UTC
|
||||
// This header was generated with sol v3.0.1-beta2 (revision 7218151)
|
||||
// Generated 2019-03-31 03:30:36.689278 UTC
|
||||
// This header was generated with sol v3.0.1-beta2 (revision 6017f63)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
@ -20,8 +20,8 @@
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// This file was generated with a script.
|
||||
// Generated 2019-03-29 03:22:11.072530 UTC
|
||||
// This header was generated with sol v3.0.1-beta2 (revision 7218151)
|
||||
// Generated 2019-03-31 03:30:35.378291 UTC
|
||||
// This header was generated with sol v3.0.1-beta2 (revision 6017f63)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
@ -4945,14 +4945,14 @@ namespace sol {
|
||||
/// \returns the stored value if there is one, otherwise returns `u`
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
constexpr T& value_or(U&& u) const& {
|
||||
constexpr T value_or(U&& u) const& {
|
||||
static_assert(std::is_copy_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be copy constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
SOL_TL_OPTIONAL_11_CONSTEXPR T& value_or(U&& u) && {
|
||||
SOL_TL_OPTIONAL_11_CONSTEXPR T value_or(U&& u) && {
|
||||
static_assert(std::is_move_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be move constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
@ -5785,16 +5785,9 @@ namespace sol {
|
||||
/// \returns the stored value if there is one, otherwise returns `u`
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
constexpr T& value_or(U&& u) const& {
|
||||
static_assert(std::is_copy_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be copy constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
/// \group value_or
|
||||
template <class U>
|
||||
SOL_TL_OPTIONAL_11_CONSTEXPR T& value_or(U&& u) && {
|
||||
static_assert(std::is_move_constructible<T>::value && std::is_convertible<U&&, T>::value, "T must be move constructible and convertible from U");
|
||||
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
|
||||
constexpr T& value_or(U&& u) const {
|
||||
static_assert(std::is_convertible<U&&, T&>::value, "T must be convertible from U");
|
||||
return has_value() ? const_cast<T&>(**this) : static_cast<T&>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
/// Destroys the stored value if one exists, making the optional empty
|
||||
|
@ -34,6 +34,10 @@
|
||||
#include <variant>
|
||||
#endif // C++17
|
||||
|
||||
struct optional_ref_t {
|
||||
int x = 0;
|
||||
};
|
||||
|
||||
std::mutex basic_init_require_mutex;
|
||||
|
||||
void basic_initialization_and_lib_open() {
|
||||
@ -114,18 +118,37 @@ TEST_CASE("utility/optional-conversion", "test that regular optional will proper
|
||||
|
||||
lua.new_usertype<vars>("vars");
|
||||
|
||||
lua["test"] = [](sol::optional<vars> x) {
|
||||
return static_cast<bool>(x);
|
||||
};
|
||||
lua["test"] = [](sol::optional<vars> x) { return static_cast<bool>(x); };
|
||||
|
||||
const auto result = lua.safe_script(R"(
|
||||
assert(test(vars:new()))
|
||||
assert(not test(3))
|
||||
assert(not test(nil))
|
||||
)", sol::script_pass_on_error);
|
||||
)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("utility/optional-value-or", "test that regular optional will properly handle value_or") {
|
||||
sol::optional<std::string> str;
|
||||
auto x = str.value_or("!");
|
||||
|
||||
sol::optional<unsigned int> un;
|
||||
auto y = un.value_or(64);
|
||||
|
||||
optional_ref_t def_custom;
|
||||
sol::optional<optional_ref_t&> custom;
|
||||
auto z = custom.value_or(def_custom);
|
||||
const auto& z_ref = custom.value_or(def_custom);
|
||||
|
||||
REQUIRE(x == "!");
|
||||
|
||||
REQUIRE(y == 64);
|
||||
|
||||
REQUIRE(&def_custom == &z_ref);
|
||||
REQUIRE(&z != &def_custom);
|
||||
}
|
||||
|
||||
TEST_CASE("utility/std optional", "test that shit optional can be round-tripped") {
|
||||
#ifdef SOL_CXX17_FEATURES
|
||||
SECTION("okay") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user