Skip to content

Unexpected behavior with fifo_map json when copy and append  #1763

Description

@DolphinDream

When copying a fifo_json to another fifo_json and appending values for new keys, different keys present in the original fifo_json are being modified instead of new keys being created.

 fifo_json j1;
 j1["Ender"] = "The Formics are intelligent";
 j1["Amstrong"] = "Walking on the moon";
 j1["Fairytale"] = "Once upon a time";

 cout << setw(2) << j1 << endl << endl;

 fifo_json jj(j1);
 // fifo_json &jj = j1; // this works fine (though perhaps because it doesn't copy)
 jj["My settings"] = {};
 jj["My settings"]["Darwin"] = "Evolution of Species";
 jj["Abracadabra"] = "Ta-Da";

 cout << setw(2) << jj << endl;

The expected result should be:

{
  "Ender": "The Formics are intelligent",
  "Amstrong": "Walking on the moon",
  "Fairytale": "Once upon a time"
}

{
  "Ender": "The Formics are intelligent",
  "Amstrong": "Walking on the moon",
  "Fairytale": "Once upon a time",
  "My settings": {
    "Darwin": "Evolution of Species"
  },
  "Abracadabra": "Ta-Da"
}

But instead I get this:

the output is:

{
  "Ender": "The Formics are intelligent",
  "Amstrong": "Walking on the moon",
  "Fairytale": "Once upon a time"
}

{
  "Ender": {
    "Darwin": "Evolution of Species"
  },
  "Amstrong": "Walking on the moon",
  "Fairytale": "Ta-Da"
}

I'm running this on the following system:

  • OS: Ubuntu 16.04.1
  • g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
  • using c++11 standard
  • json version used is: 3.3.0

And I'm using the following definitions :

// A workaround to give to use fifo_map as map, we are just ignoring the 'less' compare
template<class K, class V, class dummy_compare, class A>
using my_fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
using fifo_json = nlohmann::basic_json<my_fifo_map>;
using json = nlohmann::json;

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

    kind: bugstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions