Skip to content

transform to QJsonObject #86

Description

@hmoffatt

Is there a way to transform a QMap to a QJsonObject?

I tried this as follows, but it fails (on MSVC):

	QMap<QString, QString> values{{"hi", "there"}};
	auto js = kdalgorithms::transformed_with_new_return_type<QJsonObject>(
		values, [](const auto& item) -> std::pair<QString, QJsonValue> {
			return std::make_pair<QString, QJsonValue>(item.first, item.second);
		});

Lots of errors, including

1>C:\dev\cpp\libs\vcpkg_installed\x64-windows\include\kdalgorithms\kdalgorithms_bits\transform.h(48,60): error C2672: 'insert_wrapper': no matching overloaded function found
1>C:\dev\cpp\libs\vcpkg_installed\x64-windows\include\kdalgorithms\kdalgorithms_bits\transform.h(48,14): error C2672: 'transform': no matching overloaded function found

I also tried converting to initializer_list as QJsonObject has a constructor that accepts that, but the result was the same:

	auto js2 = kdalgorithms::transformed_with_new_return_type<std::initializer_list<std::pair<QString, QJsonValue>>>(
		values, [](const auto& item) /* -> std::pair<QString, QJsonValue>*/ {
			return std::make_pair<QString, QJsonValue>(item.first, item.second);
		});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions