Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variant is not support in Release 3.6.1? #1615

Closed
zhongcy opened this issue May 31, 2019 · 2 comments
Closed

variant is not support in Release 3.6.1? #1615

zhongcy opened this issue May 31, 2019 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@zhongcy
Copy link

zhongcy commented May 31, 2019

@nlohmann @theodelrieu
Hi, variant is not support in Release 3.6.1? Have any Variant examples?
I test the example that it's not success in Release 3.6.1.

#include "json.hpp"
#include <variant>
#include <iostream>

int main() {
	std::variant<int, float, std::string> t = 3.14159f;
	std::cout << nlohmann::json(t).dump() << std::endl;
}

variant.cpp: In function ‘int main()’: variant.cpp:17:31: error: no matching function for call to ‘nlohmann::basic_json<>::basic_json(std::variant<int, float>&)’ std::cout << nlohmann::json(t).dump() << std::endl; ^ In file included from variant.cpp:3:0: /nlohmann/json.hpp:1841:5: note: candidate: nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::basic_json(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>&&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer] basic_json(basic_json&& other) noexcept

@theodelrieu
Copy link
Contributor

Hello,

Handling std::variant has been discussed extensively in #1261, there is a complete code example that shows how to support it in a generic manner (however not optimal).

You can find the reason why we chose to not add it in the library here.

@zhongcy
Copy link
Author

zhongcy commented May 31, 2019

@theodelrieu ok, thank you.

@zhongcy zhongcy closed this as completed May 31, 2019
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants