#include <iostream>
#include <ostream>
#include <streambuf>
template <class charT, class traits>
class Fcgibuf: public std::basic_streambuf<charT, traits>
{
public:
Fcgibuf() { setp(buffer, buffer+buffSize); }
virtual ~Fcgibuf() { sync(); }
protected:
typedef typename std::basic_streambuf<charT, traits>::int_type
int_type;
typedef typename std::basic_streambuf<charT, traits>::char_type
char_type;
typedef typename std::basic_streambuf<charT,
traits>::traits_type traits_type;
int_type overflow(int_type c = traits_type::eof())
{
if(emptyBuffer() < 0)
return traits_type::eof();
if(!traits_type::eq_int_type(c, traits_type::eof()))
return sputc(c);
else
return traits_type::not_eof(c);
}
int sync() { return emptyBuffer(); }
int emptyBuffer();
static const int buffSize = 8192;
char_type buffer[buffSize];
};
template <class charT, class traits>
int Fcgibuf<charT, traits>::emptyBuffer()
{
char outBuffer[buffSize];
mbstate_t conversionState;
char_type* pStreamPos;
char* toNext;
std::use_facet said:
(this->getloc()).out(conversionState, this->pptr(), this->pbase(),
pStreamPos, (char*)outBuffer, outBuffer+buffSize, toNext);
*toNext='\0';
std::cerr << outBuffer;
pbump(-(this->pptr()-this->pbase()));
return 0;
}
int main()
{
Fcgibuf<wchar_t, std::char_traits<wchar_t> > theBuffer;
std::basic_ostream<wchar_t> theStream(&theBuffer);
theStream << L"This is a test";
return 0;
}
Upon compiling g++ gives me the following error:
tmp.cpp: In member function ‘int Fcgibuf<charT,
traits>::emptyBuffer() [with charT = wchar_t, traits =
std::char_traits<wchar_t>]’:
tmp.cpp:25: instantiated from ‘int Fcgibuf<charT, traits>::sync()
[with charT = wchar_t, traits = std::char_traits<wchar_t>]’
tmp.cpp:10: instantiated from ‘Fcgibuf<charT, traits>::~Fcgibuf()
[with charT = wchar_t, traits = std::char_traits<wchar_t>]’
tmp.cpp:51: instantiated from here
tmp.cpp:40: error: no matching function for call to
‘std::codecvt<wchar_t, char, __mbstate_t>:
ut(mbstate_t&, wchar_t*,
wchar_t*, wchar_t*&, char*, char*, char*&) const’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/codecvt.h:121:
note: candidates are: std::codecvt_base::result
std::__codecvt_abstract_base<_InternT, _ExternT,
_StateT>:
ut(_StateT&, const _InternT*, const _InternT*, const
_InternT*&, _ExternT*, _ExternT*, _ExternT*&) const [with _InternT =
wchar_t, _ExternT = char, _StateT = __mbstate_t]
This error message doesn't make very much sense to me as the candidate
seems identical to the actual function call. Can anybody shed some
light on this?