Skip to content

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

Description

@ghostplant
  • 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";
  ...
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions