Skip to content

std::chrono::duration<double> is not serializable anymore #583

@vittorioromeo

Description

@vittorioromeo

Trying to update our codebase from 0.19.0 to the latest version, but apparently std::chrono::duration<double> is not serializable anymore:

 struct TestStruct {
    std::string a = "test_value";
    std::chrono::duration<double> b = std::chrono::minutes{ 42 };
    std::chrono::milliseconds c = std::chrono::milliseconds{ 42 };
  };
  const TestStruct x{};
  const auto yaml = rfl::yaml::write(x);

The above fails with:

../parsing/Parser_duration.hpp:55:66: error: no viable conversion from 'void' to 'Unit' (aka 'Literal<"nanoseconds", "microseconds", "milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "years">')
   55 |         RType{.count = static_cast<int64_t>(_d.count()), .unit = make_unit()};
      |                                                                  ^~~~~~~~~~~
external/hephaestus++external_dependencies+reflect-cpp/include/rfl/generic/../parsing/Parser_ptr.hpp:55:59: note: in instantiation of function template specialization 'rfl::parsing::Parser<rfl::yaml::Reader, rfl::yaml::Writer, std::chrono::duration<double>, rfl::Processors<>>::write<rfl::parsing::Parent<rfl::yaml::Writer>::Object>' requested here
   55 |     Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(_w, *_ptr,
      |                                                           ^
external/hephaestus++external_dependencies+reflect-cpp/include/rfl/generic/../parsing/NamedTupleParser.hpp:202:50: note: in instantiation of function template specialization 'rfl::parsing::Parser<rfl::yaml::Reader, rfl::yaml::Writer, const std::chrono::duration<double> *, rfl::Processors<>>::write<rfl::parsing::Parent<rfl::yaml::Writer>::Object>' requested here
  202 |         Parser<R, W, ValueType, ProcessorsType>::write(_w, value, new_parent);
      |                                                  ^
external/hephaestus++external_dependencies+reflect-cpp/include/rfl/generic/../parsing/NamedTupleParser.hpp:227:6: note: in instantiation of function template specialization 'rfl::parsing::NamedTupleParser<rfl::yaml::Reader, rfl::yaml::Writer, false, false, false, rfl::Processors<>, rfl::Field<internal::StringLiteral<2>{{"a"}}, const std::string *>, rfl::Field<internal::StringLiteral<2>{{"b"}}, const std::chrono::duration<double> *>, rfl::Field<internal::StringLiteral<2>{{"c"}}, const std::chrono::duration<long long, std::ratio<1, 1000>> *>>::add_field_to_object<1>' requested here
  227 |     (add_field_to_object<_is>(_w, _tup, _ptr), ...);
      |      ^

Seems like the make_unit function is hardcoded for only long long duration types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions