jamboree / bustache

C++20 implementation of {{ mustache }}
82 stars 10 forks source link

Bustache compiles fine using nlohmann::json but not with nlohmann::ordered_json containers #26

Closed ElizabethMartinez2021 closed 2 years ago

ElizabethMartinez2021 commented 2 years ago

Not really an issue but I noticed that using nlohmann::ordered_json causes a compiler error (when rendering the template):

error C7608: atomic constraint should be a constant expression

I don't know if there are plans to allow bustache to work with ordered_json or not. Anyway, I looked at a very interesting post regarding ordered vs unordered maps: https://stackoverflow.com/questions/2196995/is-there-any-advantage-of-using-map-over-unordered-map-in-case-of-trivial-keys

Some users posted some test results for the containers. For the purpose of Bustache users, I personally do not see any benefit whatsoever of an ordered vs unordered container.

So the only applicable reason, that I could think of using an UNORDERED map would be if you wanted to save Json to a file while keeping the exact unordered or natural order as it was created. Using an ordered container means that key/value pairs will not be reordered in alphabetical order by 'key'.

Another possible benefit of orderd_json would be that someone may want to pretty print Json in its natural order for debugging purposes.

jamboree commented 2 years ago

Did you impl the traits (this and this) for nlohmann::ordered_json? It should work if the traits are properly implemented.

ElizabethMartinez2021 commented 2 years ago

Thank you Jamboree, all my tests are working properly. Template output is identical regardless of container used. Additionally, when you output the Json data, it is either ordered by 'key' or kept in natural order when using nlohmann::json or nlohmann::ordered_json containers respectively.

What I did was copy/paste the two templates you directed me to and replaced nlohmann::json with nlohman::ordered_json. Either container can be used seamlessly:


template<>
struct bustache::impl_model<nlohmann::ordered_json>
...

template<>
struct bustache::impl_compatible<nlohmann::ordered_json>
...