Skip to content

Add nlohmann::json::key_type #1951

Closed
Closed
@esraels

Description

  • Describe the feature in as much detail as possible.
    I'm planning to make a template where it accepts any kind of maps. It need to have key_type and value_type just like the map containers in STL. I want also the nlohmann::json to be supported on that template helper functions. json::value_type is already there but the key_type is not yet. I checked the latest version 3.7.3 and it is still not yet there.

Here is one of my template functions:

template<typename M> inline bool HasKey(M const& p_map, typename M::key_type const& p_key) {
	return p_map.find(p_key) != p_map.end();
}

  • Include sample usage where appropriate.
using json = nlohmann::json;

std::map mData = getSomeMapData();
if(MyLib::HasKey(mData , "keyX")){
      //found
}

json& jA = getSomeJSONData();
if(MyLib::HasKey(jA, "keyY")){
      //found
}

Metadata

Assignees

No one assigned

    Labels

    kind: enhancement/improvementstate: 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