Opened 9 years ago
Closed 9 years ago
#9483 closed Bugs (wontfix)
Can't get (translate) literal values with suffixes out of ptree
Reported by: | Owned by: | Sebastian Redl | |
---|---|---|---|
Milestone: | To Be Determined | Component: | property_tree |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | ptree literal suffix | Cc: | ricardolafabreu@… |
Description
Hello,
I just figured that the property_tree lib cannot translate some acceptable literals. Here is an example to show this:
#include <boost/property_tree/ptree.hpp> #include <boost/optional.hpp> #include <iostream> using namespace boost::property_tree; using namespace std; void printo(boost::optional<long long> o, const std::string & name) { if(o) cout << name << " is: " << *o << endl; else cerr << "couldn't get " << name << endl; } int main() { ptree p; p.put("good_long_long", "0"); long long test1 = 0; // show that 0 is an acceptable long long literal p.put("bad_long_long", "0LL"); long long test2 = 0LL; // show that 0LL is an acceptable long long literal auto good = p.get_optional<long long>("good_long_long"); auto bad = p.get_optional<long long>("bad_long_long"); printo(good, "good"); printo(bad, "bad"); return 0; }
Apparently the stream_translator doesn't consume the 'L's and then the test iss.get() != Traits::eof()
, in stream_translator.hpp, is true, resulting in an empty optional.
Please feel free to contact me. I hope not, but I'm sorry if there is something stupid I am missing.
Cheers, Ricardo Abreu
Note:
See TracTickets
for help on using tickets.
The stream_translator, as it name indicates, uses an iostream (specifically, a stringstream) to convert data. It is therefore compatible with the data formats supported by iostreams. C++ language integer literal syntax is not supported by streams, and thus isn't supported by the stream_translator. If you need compatibility with such formats, you need to write your own translator.