Abhijit
Abhijit

Reputation: 63737

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 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.

Upvotes: 0

Views: 1176

Answers (0)

Related Questions