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

How to use json parse in tsl::ordread_map? #1934

Closed
continue98 opened this issue Feb 11, 2020 · 4 comments
Closed

How to use json parse in tsl::ordread_map? #1934

continue98 opened this issue Feb 11, 2020 · 4 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@continue98
Copy link

continue98 commented Feb 11, 2020

How to use json parse from fstream?

1>------ Build started: Project: ConsoleApplication9, Configuration: Debug Win32 ------
1>ConsoleApplication9.cpp
1>\3rd-party\json\json.hpp(9592,1): error C2440: 'return': cannot convert from 'const _Ty2 *' to 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> *'
1>        with
1>        [
1>            _Ty2=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1>        ]
1>\3rd-party\json\json.hpp(9592,24): message : Conversion loses qualifiers
1>\3rd-party\json\json.hpp(9584): message : while compiling class template member function 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> *nlohmann::detail::iter_impl<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::operator ->(void) const'
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(4750): message : see reference to function template instantiation 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> *nlohmann::detail::iter_impl<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::operator ->(void) const' being compiled
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(4748): message : see reference to class template instantiation 'nlohmann::detail::iter_impl<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>' being compiled
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(4733): message : while compiling class template member function 'bool nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>::end_object(void)'
1>        with
1>        [
1>            BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1>        ]
1>\3rd-party\json\json.hpp(8847): message : see reference to function template instantiation 'bool nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>::end_object(void)' being compiled
1>        with
1>        [
1>            BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1>        ]
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(8737): message : see reference to class template instantiation 'nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>' being compiled
1>        with
1>        [
1>            BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1>        ]
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(8734): message : while compiling class template member function 'void nlohmann::detail::parser<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::parse(const bool,BasicJsonType &)'
1>        with
1>        [
1>            BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1>        ]
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(20750): message : see reference to function template instantiation 'void nlohmann::detail::parser<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::parse(const bool,BasicJsonType &)' being compiled
1>        with
1>        [
1>            BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1>        ]
1> 3rd-party\json\json.hpp(15661): message : see reference to class template instantiation 'nlohmann::detail::parser<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>' being compiled
1>C:\Users\continue\source\repos\ConsoleApplication9\ConsoleApplication9\ConsoleApplication9.cpp(19): message : see reference to class template instantiation 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>' being compiled
1>Done building project "ConsoleApplication9.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Code:

#include <iostream>
#include "json.hpp"
#include "ordered_map.hxx"
#include <fstream>
template<class Key, class T, class Ignore, class Allocator,
    class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
    class AllocatorPair = typename std::allocator_traits<Allocator>::template rebind_alloc<std::pair<Key, T>>,
    class ValueTypeContainer = std::vector<std::pair<Key, T>, AllocatorPair>>
    using ordered_map = tsl::ordered_map<Key, T, Hash, KeyEqual, AllocatorPair, ValueTypeContainer>;

using json = nlohmann::basic_json<ordered_map>;

int main()
{
    std::ifstream file("1");
    json j;
    j.parse(file);
}
@continue98 continue98 changed the title How to use tl How to use json parse in tsl::ordread_map? Feb 11, 2020
@stale
Copy link

stale bot commented Mar 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Mar 12, 2020
@dota17
Copy link
Contributor

dota17 commented Mar 18, 2020

Related Issue: #546
Other helpful Issue: #727 , #485

@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Mar 18, 2020
@dota17
Copy link
Contributor

dota17 commented Mar 19, 2020

This is the example with fifo_map:
#485 (comment)

And, i had changed fifo_map to tsl::ordered_map and it works :
Before:

using namespace nlohmann;

// A workaround to give to use fifo_map as map, we are just ignoring the 'less' compare
template<class K, class V, class dummy_compare, class A>
using my_workaround_fifo_map = fifo_map<K, V, fifo_map_compare<K>, A>;
using my_json = basic_json<my_workaround_fifo_map>;

...

After:

template<class Key, class T, class Ignore, class Allocator,
    class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
    class AllocatorPair = typename std::allocator_traits<Allocator>::template rebind_alloc<std::pair<Key, T>>,
    class ValueTypeContainer = std::vector<std::pair<Key, T>, AllocatorPair>>
    using ordered_map = tsl::ordered_map<Key, T, Hash, KeyEqual, AllocatorPair, ValueTypeContainer>;

using json = nlohmann::basic_json<ordered_map>;

...

Their outputs are same:

{"f":5,"a":2}
{"pi":3.141,"happy":true,"name":"Niels","nothing":null,"answer":{"everything":42},"list":[1,0,2],"object":{"currency":"U
SD","value":42.99}}

My env is VS2017, both are OK for me.

@nlohmann
Copy link
Owner

@continue98 Do you need further assistance?

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Apr 11, 2020
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