5 ms·
This doesn't appear to be all that "modern": it doesn't support string_view for lookup without extra allocations, and it doesn't support unordered_map (or even
by esprehn 5y ago
This doesn't appear to be all that "modern": it doesn't support string_view for lookup without extra allocations, and it doesn't support unordered_map (or even use it as the default) for objects.
It seems they're targeting C++11?
- howolduis 5y agopeople love to complain
- q-rews 5y agoPeople love correct statements. C++11 was release 10 years ago and there are 3 newer versions.
- rualca 5y ago> people love to complain Do you find it unreasonable to point out that what's been advertised doesn't match what's being offered?
- nlohmann 5y agoAs I tried to describe earlier: "modern C++" is not necessarily "using the latest standard", but rather "C++ since it was updated with C++11 (and later)".
- rualca 5y agoAiming at C++11 is not a reasonable definition of "modern", as it was C++'s second ISO standard that was published a decade ago and which has since seen between two and three major updates (depending on the opinions on c++14)
- nlohmann 5y agoIt's not the "aiming at C++11", but rather "Write code that does not look odd in a code base that is using constructs from C++11, C++14, C++17, etc." - The library uses C++11 to implement an API that should not feel weird when used together with other containers from the STL.
- bobnamob 5y agoIn C++ land "modern" has become synonymous with post 11. Effectively a domain specific definition. Reasonable considering the difference between pre and post 11. Pre and post 20 will probably be treated similarly in a decade
- maleldil 5y agoC++11 was a huge shift in how C++ is written, and term coined for "code written using the new techniques" was "Modern C++". Whether you think that term should instead mean "the latest C++ version" is a different matter altogether.
- beached_whale 5y agoThe C++11 is still common enough that if you want a large usage group it's the target. However, it's parsing to a DOM and doesn't use features like PMR, so the language features needed won't be more than std containers and stuff.
- pjmlp 5y agoSpecially among the C+ community groups.
- beached_whale 5y agoIt is changing and I saw some survey’s showing 17 around 1/2 the shops. I know for my JSON library it wouldn’t be possible without C++ 17 so it’s a loss of eyes
- pjmlp 5y agoYeah, thing is how much C++17 is actually used beyond the language version. For example, C++/WinRT is a C++17 library, yet plenty of samples use C style strings and vectors.
- beached_whale 5y agoI use a lot of core C++17 isms. They make some things doable and others clearer. But I think C++17 really helped a lot in generic programming in addition to the containers it introduced.
- quietbritishjim 5y agoI think it makes sense to target C++11. Just that you shouldn't then call the library "modern".
- nlohmann 5y agoThere is also a SAX parser. But to be honest, I have not yet played around with PMR.
- pjmlp 5y agoFor many even using RAII, which even Turbo Vision for MS-DOS made use of, is already "modern".
- MauranKilom 5y ago> and it doesn't support unordered_map (or even use it as the default) for objects. std::unordered_map has massive overhead in space and time. Maybe I misunderstand your idea, but outside of extremely niche use cases, std::unordered_map is basically never the right tool (unless you don't care in the slightest about performance or memory overhead).
- agent327 5y agoSource? A hash map should in principle be faster than a tree, with far fewer comparisons, and against a computed hash value instead of the whole object, in principle.
- einpoklum 5y agoWell, std::unordered_map is faster than than std::map, but it is still slow, since it uses lists for its buckets, with lots of dynamic allocation. See also: https://stackoverflow.com/a/42588384/1593077 https://stackoverflow.com/a/42588384/1593077 and the link there. Not sure that's what GP meant though.
- agent327 5y agoI don't believe it has to, some kind of bucket-optimisation (multiple elements per allocation, instead of one element per allocation) should also meet all constraints the standard sets for this type. And I don't like it when people use ridiculous hyperbole to describe what is in reality barely perceptible overhead, so it would be good if the person I originally responded to came out and defended his POV. Hopefully using actual numbers instead of agitated handwaving and screaming...
- beached_whale 5y agoAbseil has a btree based hash map and it performs much better. I think it maintains the same constrains(iterator invalidation/exception safety...) as std::unordered_map. The issue is that the implementors won't change their implementation of unordered_map as it's an ABI break, to say it simply. It could be better. But also, there are other tools like flat maps/open addressing that are not done in the std library.
- mike_hock 5y agoIt uses the ordering of std::map for its own comparison operators and hash function.
- nlohmann 5y agoThe development started in 2013 when C++11 was still modern. Since then, the term "modern C++" is, to my understanding, a synonym for "C++11 and later". Of course, some code may look dated compared to newer C++ constructs, but the main goal is to integrate JSON into any C++ code bases without making it look odd. The string_view lookup is nearly done, but I did not want to wait for it, because it would have delayed the release even more. I'm also working on supporting unordered_map - using it as container for objects would be easy if we would just break the existing API - the hard part is to support it with the current (probably bad designed) template API.
- adzm 5y agoYou can provide alternative collections if needed by templating basic_json; std::map is just a default. Personally I like using a flat_map which is an ordered map built on top of a vector, which provides nice cache locality and is generally even faster than a hash map / unordered_map except for extremely large objects.