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 in ootest::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

  1. why doesn't construction via std::istreambuf_iterator<char> doesn't match?
  2. what macro _rwstd_no_member_templates for?

note

  1. 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_templates didn't help.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -