Make all Literal default-constructible; fixes #536 (#539)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-11-03 22:47:19 +01:00
committed by GitHub
parent e47dfbeb1f
commit 920caef563
2 changed files with 19 additions and 4 deletions
-4
View File
@@ -45,10 +45,6 @@ class Literal {
Literal(const std::string& _str) : value_(find_value(_str).value()) {}
/// A single-field literal is special because it
/// can also have a default constructor.
template <ValueType num_fields = num_fields_,
typename = std::enable_if_t<num_fields <= 1>>
Literal() : value_(0) {}
~Literal() = default;
+19
View File
@@ -0,0 +1,19 @@
#include <chrono>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include "rfl/DefaultIfMissing.hpp"
#include "write_and_read.hpp"
namespace test_duration_default {
struct TestStruct {
std::chrono::seconds duration;
};
TEST(json, test_duration_default) {
const auto test = TestStruct{.duration = std::chrono::seconds(10)};
write_and_read<rfl::DefaultIfMissing>(
test, R"({"duration":{"count":10,"unit":"seconds"}})");
}
} // namespace test_duration_default