-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Unexpected behavior with fifo_map json when copy and append #1763
Comments
It seems that if i make the copy this way it works fine:
so, something may be buggy with the way the other copy constructors work:
|
I think I found the issue. I believe it is actually a bug in the fifo_map library. That is why on the first time you insert on a copied fifo_json it looks like the first element is being overwritten. This really small patch fixes the issues since it copies over the whole object instead of just the keys, without updating the timestamp. diff --git a/test/thirdparty/fifo_map/fifo_map.hpp b/test/thirdparty/fifo_map/fifo_map.hpp
index c281e3be..1667dd2e 100644
--- a/test/thirdparty/fifo_map/fifo_map.hpp
+++ b/test/thirdparty/fifo_map/fifo_map.hpp
@@ -126,7 +126,7 @@ template <
fifo_map() : m_keys(), m_compare(&m_keys), m_map(m_compare) {}
/// copy constructor
- fifo_map(const fifo_map &f) : m_keys(f.m_keys), m_compare(&m_keys), m_map(f.m_map.begin(), f.m_map.end(), m_compare) {}
+ fifo_map(const fifo_map &f) : m_keys(f.m_keys), m_compare(f.m_compare), m_map(f.m_map.begin(), f.m_map.end(), m_compare) {}
/// constructor for a range of elements
template<class InputIterator>
I also have some unit tests to show it but since this is a bug on third-party library I am not sure where to submit it. PS: If any thing of this is not clear enough please let me know I am written this in a rush before going to bed so it may not be the best explanation but I am open to explain better if necessary 😄 |
I leave my branch with my fixes as a proof but is not yet ready for merging since I still have to add the |
It even looks like to be fixed upstream https://github.com/nlohmann/fifo_map/blob/0dfbf5dacbb15a32c43f912a7e66a54aae39d0f9/src/fifo_map.hpp#L146 Time to update dependencies? |
Any idea how to proceed here? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Which is the better fix for 3.3.0 though ? the one you proposed earlier m_compare(f.m_compare) .. or the one you suggested it was already fixed upstream m_compare(&m_keys, f.m_compare.m_timestamp) ? Note: upgrading to a newer version of json library is not feasible at this point.. but a small bug fix is more doable, hence my question. |
is fifo_map still the way to go to create json objects preserving order of insertion ? or is there a different approach? (unorderd map? unordered json etc?) |
There is now ordered_json, see https://json.nlohmann.me/api/ordered_json/ |
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.
The expected result should be:
But instead I get this:
the output is:
I'm running this on the following system:
And I'm using the following definitions :
The text was updated successfully, but these errors were encountered: