Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from valarray<double> to json fails to build #702

Closed
popizdeh opened this issue Aug 21, 2017 · 3 comments
Closed

Conversion from valarray<double> to json fails to build #702

popizdeh opened this issue Aug 21, 2017 · 3 comments
Assignees
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@popizdeh
Copy link

popizdeh commented Aug 21, 2017

There seems to be a regression from 2.0.8 and 2.1.1. This no longer compiles.

std::valarray<double> v;
nlohmann::json j;
j["test"] = v;

P.S. Is there any chance we can get a release with std::vector fix released?

@theodelrieu
Copy link
Contributor

Oops, this is due to the has_iterator traits that check for a iterator type alias, which valarray doesn't provide. Sorry about that.

namespace nlohmann
{
template <typename T>
struct adl_serializer<std::valarray<T>>
{
  static void to_json(json &j, std::valarray<T> const &v)
  {
    detail::external_constructor<detail::value_t::array>::construct(j, v);
  }

  static void from_json(json const &j, std::valarray<T> &v)
  {
    // checks omitted, not the best implem, never played with valarray myself
    auto arr = j.get<std::vector<T>>();
    v = std::valarray<T>(arr.data(), arr.size());
  }
};
}

As for the bug fix release, I don't know what @nlohmann thinks about it.

@nlohmann
Copy link
Owner

We need to fix this and add std::valarray support for the 3.x.x release. I did not plan to create a bug fix release for this.

@nlohmann nlohmann self-assigned this Aug 22, 2017
@nlohmann nlohmann added this to the Release 3.0.0 milestone Aug 22, 2017
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Aug 22, 2017
@nlohmann
Copy link
Owner

Fixed with 9fd031b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants