From 58e32e173b76450ead43f095aee1f8650aae2fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Wed, 13 Mar 2024 12:13:31 +0100 Subject: [PATCH] Disable nil_value() for enum and remove NilValue. Fixes: https://github.com/prusa3d/PrusaSlicer/issues/12455. --- src/libslic3r/Config.hpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 24bbe7a5b1..c3e4ac2c8f 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -324,7 +324,6 @@ typedef const ConfigOption* ConfigOptionConstPtr; template struct NilValueTempl { using NilType = T; - static_assert(always_false::value, "Type has no well defined nil value"); }; template struct NilValueTempl, void>> { @@ -334,14 +333,6 @@ template struct NilValueTempl template<> struct NilValueTempl : public NilValueTempl{}; -// For enums the nil is the max value of the underlying type. -template -struct NilValueTempl, void>> -{ - using NilType = T; - static constexpr auto value = static_cast(std::numeric_limits>::max()); -}; - template struct NilValueTempl, void>> { using NilType = T; static constexpr auto value = std::numeric_limits::quiet_NaN(); @@ -375,7 +366,7 @@ public: T value; explicit ConfigOptionSingle(T value) : value(std::move(value)) {} operator T() const { return this->value; } - + void set(const ConfigOption *rhs) override { if (rhs->type() != this->type()) @@ -440,7 +431,8 @@ public: bool nullable() const override { return NULLABLE; } - static constexpr NilType nil_value() { return NilValue(); } + template = true> + static constexpr NilType nil_value() { return NilType(); } // A scalar is nil, or all values of a vector are nil. bool is_nil() const override @@ -717,7 +709,7 @@ public: std::istringstream iss(str); if (str == "nil") { - if (NULLABLE) + if constexpr (NULLABLE) this->value = this->nil_value(); else throw ConfigurationError("Deserializing nil into a non-nullable object"); @@ -890,7 +882,8 @@ public: std::string serialize() const override { std::ostringstream ss; - if (this->value == this->nil_value()) { + + if (this->value == std::numeric_limits::max()) { if (NULLABLE) ss << "nil"; else @@ -907,7 +900,7 @@ public: std::istringstream iss(str); if (str == "nil") { - if (NULLABLE) + if constexpr (NULLABLE) this->value = this->nil_value(); else throw ConfigurationError("Deserializing nil into a non-nullable object");