Я не думаю, что отказ от #include принесет вам реальную выгоду, но вот как вы можете это сделать:
namespace std {
template<class Char>
struct char_traits;
template<class T>
struct allocator;
template<class Char, class Traits, class Allocator>
struct basic_string;
typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >
wstring;
}
// simple test that it's compatible:
std::wstring *p; // incomplete type at this point, but you can have a pointer
#include <string>
int main() {
std::wstring s = L"Hello, world!";
p = &s;
return 0;
}
Вы должны быть осторожны с параметрами по умолчанию;в частности, это не будет работать:
namespace std {
template<class Char>
struct char_traits;
template<class T>
struct allocator;
template<class Char, class Traits=char_traits<Char>,
class Allocator=allocator<Char> >
struct basic_string;
typedef basic_string<wchar_t> wstring;
}
#include <string>
Скомпилировано с включением показывает несовместимость:
In file included from /usr/include/c++/4.4/string:41,
from example.cpp:15:
/usr/include/c++/4.4/bits/stringfwd.h:52: error: redefinition of default argument for ‘class _Traits’
example.cpp:8: note: original definition appeared here