The following innocuous function fails to 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 with the error message
Could not find a match for
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 I checked the file std::string and found the following
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
template <class _InputIterator>
basic_string (_InputIterator, _InputIterator, const _Allocator& _RWSTD_DEFAULT_ARG(_Allocator()));
SO I guess, std::string has a declaration for the 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 it didn't.
So I have two questions
- Why doesn't my construction via
std::istreambuf_iterator<char>doesn't match? - What is this macro
_RWSTD_NO_MEMBER_TEMPLATESfor?
Note
- Based on the comment, I tried to generate the pre-processor output by running
CC -E test.cpp > pre.outand found, the iterator version was not generated. So I tried undefining_RWSTD_NO_MEMBER_TEMPLATESbut that didn't help.