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

Error: "tuple_size" has already been declared in the current scope #1466

Closed
gregha opened this issue Jan 30, 2019 · 2 comments
Closed

Error: "tuple_size" has already been declared in the current scope #1466

gregha opened this issue Jan 30, 2019 · 2 comments

Comments

@gregha
Copy link

gregha commented Jan 30, 2019

I added the following lines of code to my current project:

#include <nlohmann/json.hpp>
using json = nlohmann::json;
// ...
void Model::initJSONData(json::json &json_data, std::string path_to_file)
{
  std::ifstream json_file_stream(path_to_file.c_str());
  if(!json_file_stream.is_open())
    throw std::runtime_error("JSON file DTModelDatabase.json could not be opened.");
  json_file_stream >> json_data;
  json_file_stream.close();
}

However, I get the following error:

".../include/json/include/nlohmann/detail/iterators/iteration_proxy.hpp", line 151: error: 
          "tuple_size" has already been declared in the current scope
  class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
        ^

As can be seen, the error originates from the header-file iteration_proxy.hpp. Is it possible that there is a conflict with the already defined tuple_size in std? I run a Red Hat Enterprise Linux with GCC 6.3.0 (c++11 is set). Can anybody help me out with this error?

@nickaein
Copy link
Contributor

I've tested your snippet on my machine (GCC 7.3) and it worked. I just had to remove json:: prefix from json_data argument.

I've also tested it on GCC 6.3 and GCC 6.2 on godbolt and it also works. You can verify the godbolt instance here: https://godbolt.org/z/oM7Vs8.

Maybe there is something else that are interfering which is not present in this code snippet?

@gregha
Copy link
Author

gregha commented Jan 31, 2019

Thanks for testing my code snippet. I tested the project I am working on now for different versions of this JSON library, producing even other errors like:

"/home/ceres_ns_scratch5/nxf36874/TAG180628_AHB/ss_solver_new_json/include/json/include/nlohmann/detail/conversions/to_json.hpp", line 301: error: 
          too few arguments for class template "std::pair"
  void to_json(BasicJsonType& j, const std::pair<Args...>& p)
                                                        ^

Thus, as you stated as well, the error is most probably not due to the library or due to the way I use it, but somewhere else in the project.

@gregha gregha closed this as completed Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants