Skip to content
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

To integrate an inline helper function that return type name as string #1632

Closed
ghostplant opened this issue Jun 11, 2019 · 2 comments
Closed
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@ghostplant
Copy link

  • Describe the feature in as much detail as possible.
    To integrate an inline helper function that return type name as string.

  • Include sample usage where appropriate.
    It helps for many runtime requirement, not only for debugging type data when logging, but also for transferring type information as message to other program components that is not with nlohmann library integrated. Using is_number(), is_array() and .. case by case is a lot more verbose which is unfriendly for those requirement.

The solution should be simple, and it is recommended to integrate into the library itself:

inline std::string json::type_as_string() {
  if (this->is_bool())
    return "bool";
  if (this->is_number_integer())
    return "int";
  if (this->is_number_float())
    return "float";
  ...
}
@nickaein
Copy link
Contributor

This is already basic_json::type_name() method available for JSON objects. Does that accomplish what you are looking for?

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed kind: enhancement/improvement labels Jun 11, 2019
@ghostplant
Copy link
Author

@nickaein Thanks, it is just a little hard to find such usage from the documentation and I think it is too hidden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants