c++ - Could not find a match for std::string::basic_string(std::istreambuf_iterator<char, std::char_traits<char>>, std::istreambuf_iterator<char, std:: -
the following innocuous function fails compile on solaris studio 12.3
#undef _rwstd_no_member_templates #include <fstream> #include <string> #define _rwstd_no_member_templates std::string fetchdata(const std::string& fname) { std::ifstream fin(fname.c_str()); std::string data; if (fin) { data = std::string((std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>()); } return data; } int main() { return 0; } which fails error message
could not find match
std::string::basic_string(std::istreambuf_iterator<char, std::char_traits<char>>, std::istreambuf_iterator<char, std::char_traits<char>>)needed inootest::fetchdata(const std::string &).
now checked file std::string , found following
#ifndef _rwstd_no_member_templates template <class _inputiterator> basic_string (_inputiterator, _inputiterator, const _allocator& _rwstd_default_arg(_allocator())); so guess, std::string has declaration overload
template< class inputit > basic_string( inputit first, inputit last, const allocator& alloc = allocator() ); which should have matched
template< class inputit > basic_string( inputit first, inputit last, const allocator& alloc = allocator() ); but unfortunately didn't.
so have 2 questions
- why doesn't construction via
std::istreambuf_iterator<char>doesn't match? - what macro
_rwstd_no_member_templatesfor?
note
- based on comment, tried generate pre-processor output running
cc -e test.cpp > pre.out, found, iterator version not generated. tried undefining_rwstd_no_member_templatesdidn't help.
Comments
Post a Comment