Skip to content

Addint support for complex type #2207

Description

@pfeatherstone

Could we add official support for complex type. I don't know if this requires a fully blown PR as the code is so small:

namespace std {
    template<typename R, typename std::enable_if<std::is_arithmetic<R>::value>::type* = nullptr>
    void to_json(nlohmann::json& j, const complex<R>& d)
    {
        j = {d.real(), d.imag()};
    }

    template<typename R, typename std::enable_if<std::is_arithmetic<R>::value>::type* = nullptr>
    void from_json(const nlohmann::json& j, complex<R>& d)
    {
        d.real(j.at(0).get<R>());
        d.imag(j.at(1).get<R>());
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions