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

compiler error with std::string = ponder::Value #82

Open
shierei opened this issue May 31, 2017 · 3 comments
Open

compiler error with std::string = ponder::Value #82

shierei opened this issue May 31, 2017 · 3 comments

Comments

@shierei
Copy link
Contributor

shierei commented May 31, 2017

From the document, it looks like I should be able to assign a ponder::Value to a std::string but I get the following compiler error.

 error: ambiguous overload for ?operator=? (operand types are ?std::string {aka std::basic_string<char>}? and ?ponder::Value?)
     std::string s = john.get("age");
       ^
/root/ponder/test/examples/simple.cpp:103:7: note: candidates are:
In file included from /opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/string:52:0,
                 from /root/ponder/test/examples/simple.cpp:29:
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/bits/basic_string.h:554:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
       operator=(const basic_string& __str) 
       ^
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/bits/basic_string.h:562:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
       operator=(const _CharT* __s) 
       ^
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/bits/basic_string.h:573:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
       operator=(_CharT __c) 
       ^
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/bits/basic_string.h:589:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(std::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
       operator=(basic_string&& __str)
       ^
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.1/bits/basic_string.h:601:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(std::initializer_list<_Tp>) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
       operator=(initializer_list<_CharT> __l)

Is this expected?

@shierei
Copy link
Contributor Author

shierei commented May 31, 2017

Using john.get("age").to<std::string>() to convert works.

@shierei shierei closed this as completed May 31, 2017
@billyquith
Copy link
Owner

If the documentation is incorrect or unclear could you please add a link to the page and what is unclear or wrong. Thanks.

@billyquith billyquith reopened this Jun 1, 2017
@shierei
Copy link
Contributor Author

shierei commented Jun 2, 2017

The document that I was referring to is here https://billyquith.github.io/ponder/docs/classponder_1_1_value.html#details.

  • The Value class can store any type of variable, and supports conversion
  • to any type compatible with the stored type.
  • \code
  • camp::Value v1 = true;
  • camp::Value v2 = 10;
  • camp::Value v3 = "24.5";
  • camp::Value v4 = myObject;
  • bool b = v1; // b == true
  • std::string s = v2; // s == "10"
  • float f = v3; // f == 24.5
  • MyObject o = v4; // o == myObject

Based on this, you might think that the assignment would do the type conversion when assigning a number string to a number directly. It does not compile. This is no big deal because class ponder::Value overloads operator T() and it does the conversion correctly for other cases, such as passing a Value to a function argument of a string or a number type.

@billyquith billyquith self-assigned this Jun 3, 2017
@billyquith billyquith added this to the 3.0 - Big refactor milestone Apr 29, 2018
@billyquith billyquith added the bug label Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants