billyquith / ponder

C++ reflection library with Lua binding, and JSON and XML serialisation.
http://billyquith.github.io/ponder/
Other
633 stars 92 forks source link

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

Open shierei opened 7 years ago

shierei commented 7 years ago

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 commented 7 years ago

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

billyquith commented 7 years ago

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

shierei commented 7 years ago

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

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.