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

find_or is ambiguous for double and bool #70

Open
yomichi opened this issue Jun 19, 2019 · 3 comments
Open

find_or is ambiguous for double and bool #70

yomichi opened this issue Jun 19, 2019 · 3 comments

Comments

@yomichi
Copy link

yomichi commented Jun 19, 2019

Calling find_or for double or bool is ambiguous while calling for int or string works well.

#include "../toml.hpp"
int main(){
  auto data = toml::parse("data.toml");
  auto N = toml::find_or(data, "int", 2);
  auto r = toml::find_or(data, "double", 1.0);
  auto b = toml::find_or(data, "bool", true);
  auto s = toml::find_or(data, "string", "foo");
}

Error message by Apple Clang is the following (GCC-9 says the similar message):

$ g++ --std=c++11 main.cpp
main.cpp:7:12: error: call to 'find_or' is ambiguous
  auto r = toml::find_or(data, "double", 1.0);
           ^~~~~~~~~~~~~
./../toml/get.hpp:588:5: note: candidate function [with T = double, $1 = nullptr]
T&& find_or(toml::value&& v, const toml::key& ky, T&& opt)
    ^
./../toml/get.hpp:661:10: note: candidate function [with T = double, $1 = nullptr]
T const& find_or(const toml::table& tab, const toml::key& ky, const T& opt)
         ^
./../toml/get.hpp:568:10: note: candidate function [with T = double, $1 = nullptr]
T const& find_or(const toml::value& v, const toml::key& ky, const T& opt)
         ^
main.cpp:8:12: error: call to 'find_or' is ambiguous
  auto b = toml::find_or(data, "bool", true);
           ^~~~~~~~~~~~~
./../toml/get.hpp:588:5: note: candidate function [with T = bool, $1 = nullptr]
T&& find_or(toml::value&& v, const toml::key& ky, T&& opt)
    ^
./../toml/get.hpp:661:10: note: candidate function [with T = bool, $1 = nullptr]
T const& find_or(const toml::table& tab, const toml::key& ky, const T& opt)
         ^
./../toml/get.hpp:568:10: note: candidate function [with T = bool, $1 = nullptr]
T const& find_or(const toml::value& v, const toml::key& ky, const T& opt)
         ^
2 errors generated.

Even if I declare data as toml::table explicitly, the problem still occurs.

Both the latest develop version (dee32e7) and the latest release (v2.3.1) of toml11 face this problem.

(By the way, could you put find_or into README?)

@ToruNiina
Copy link
Owner

Thank you for reporting!

I reproduced the error on my local environment. I think I understand why it is ambiguous, but currently don't have any idea to solve this without breaking the backward compatibility.

But I have one quick workaround. By receiving the result of toml::parse as a toml::value, the ambiguity would be resolved.

toml::value data = toml::parse("data.toml");

I will try to resolve this, but it takes some time...

@yomichi
Copy link
Author

yomichi commented Jun 20, 2019

Thank you for giving the workaround, this seems to work in my usage!

@xgdgsc
Copy link

xgdgsc commented Apr 19, 2020

Thanks for the workaround, hoping it can be fixed.

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

3 participants