0

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

  1. Why doesn't my construction via std::istreambuf_iterator<char> doesn't match?
  2. What is this macro _RWSTD_NO_MEMBER_TEMPLATES for?

Note

  1. Based on the comment, I tried to generate the pre-processor output by running CC -E test.cpp > pre.out and found, the iterator version was not generated. So I tried undefining _RWSTD_NO_MEMBER_TEMPLATES but that didn't help.
Abhijit
  • 62,056
  • 18
  • 131
  • 204
  • 2
    Can you check preprocessor output to see if that macro is in fact skipping that constructor declaration? – aschepler Aug 18 '14 at 06:45
  • @aschepler: As per the pre-processor output, the iterator version of the constructor was not generated, so I tried undefining the macro _RWSTD_NO_MEMBER_TEMPLATES , but that didn't help – Abhijit Aug 18 '14 at 07:27
  • Your standard library implementation is probably outdated. Use a different implementation. See [here](https://community.oracle.com/message/9936913). – n. m. could be an AI Aug 18 '14 at 11:45
  • Hello, did you find a solution for that problem which I am also facing? – Adel Boutros Jan 19 '16 at 17:12

0 Answers0