Skip to content
This repository was archived by the owner on Mar 26, 2020. It is now read-only.
This repository was archived by the owner on Mar 26, 2020. It is now read-only.

auto casting #130

@weepy

Description

@weepy

I added the following to json11.hpp

 /// @weepy additions
        operator long() {
            return (long) int_value();
        }
        
        operator int() {
            return int_value();
        }
        operator float() {
            return (float) number_value();
        }
        operator double() {
            return (double) number_value();
        }
        operator std::string() {
            return string_value();
        }
        operator bool() {
            return bool_value();
        }
        
        operator object() {
            return object_items();
        }
        
        operator array() {
            return array_items();
        }

It makes using json11 much more convenient as the compiler will auto cast your variables for you, eg:
int id = myJson["id"];

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions