nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.97k stars 6.72k forks source link

why I can return tuple as json? #3961

Closed tesla1060 closed 1 year ago

tesla1060 commented 1 year ago

Description

I am wonder why below code can be compiled

#include "json.hpp"
#include <iostream>
using json = nlohmann::json;

std::tuple<bool, json> test() {
    json j;
    j["name"]="a";
    return std::make_tuple(true, j);
}

int main() {
    json j;
    j = test();
    std::cout << j.contains("name") << std::endl;
}

Reproduction steps

code supplied description.

Expected vs. actual results

I am expecting a compile time failure, while the above code can actually compiled and run

Minimal code example

No response

Error messages

No response

Compiler and operating system

ubuntu 20

Library version

gcc 9

Validation

nlohmann commented 1 year ago

See https://json.nlohmann.me/api/macros/json_use_implicit_conversions/

Can you try to compile with

#define JSON_USE_IMPLICIT_CONVERSIONS 0