Skip to content

Commit 920caef

Browse files
Make all Literal default-constructible; fixes #536 (#539)
1 parent e47dfbe commit 920caef

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

include/rfl/Literal.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class Literal {
4545

4646
Literal(const std::string& _str) : value_(find_value(_str).value()) {}
4747

48-
/// A single-field literal is special because it
49-
/// can also have a default constructor.
50-
template <ValueType num_fields = num_fields_,
51-
typename = std::enable_if_t<num_fields <= 1>>
5248
Literal() : value_(0) {}
5349

5450
~Literal() = default;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <chrono>
2+
#include <rfl.hpp>
3+
#include <rfl/json.hpp>
4+
5+
#include "rfl/DefaultIfMissing.hpp"
6+
#include "write_and_read.hpp"
7+
8+
namespace test_duration_default {
9+
10+
struct TestStruct {
11+
std::chrono::seconds duration;
12+
};
13+
14+
TEST(json, test_duration_default) {
15+
const auto test = TestStruct{.duration = std::chrono::seconds(10)};
16+
write_and_read<rfl::DefaultIfMissing>(
17+
test, R"({"duration":{"count":10,"unit":"seconds"}})");
18+
}
19+
} // namespace test_duration_default

0 commit comments

Comments
 (0)