Skip to content

Compilation error occurs when using nlohmann::ordered_map #5122

@wangbw1116

Description

@wangbw1116

Description

When I use macro 'NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT' to transfer ordered_json to class, the class contains a nlohmann::ordered_map, compile error

Reproduction steps

#include <iostream>
#include <nlohmann/json.hpp>

using namespace std;
using nlohmann::ordered_json;
using nlohmann::ordered_map;

struct J_Data {
    float b = 2;
    ordered_map<string, string> c;
    int a = 1;
    NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(J_Data, b, c, a)
};

int main() {
    J_Data data1;
    ordered_json j = data1;
    cout << "j: " << j << endl;

    J_Data data2 = j;
    cout << "j: " << j << endl;
    return 0;
}

compiler error:
/usr/include/c++/10/bits/stl_algobase.h:380:18: error: use of deleted function ‘std::pair<const std::__cxx11::basic_string, std::__cxx11::basic_string >& std::pair<const std::__cxx11::basic_string, std::__cxx11::basic_string >::operator=(const std::pair<const std::__cxx11::basic_string, std::__cxx11::basic_string >&)’
380 | *__result = *__first;

Expected vs. actual results

fix the bug

Minimal code example

Error messages

Compiler and operating system

ubuntu20

Library version

gcc version 10.5.0

Validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions