Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string_char_traits<char> in C++11 for GNU/G++ 4.9 (earlier 2.95.3)

I have some legacy C++ code (used to compile using GNU g++ 2.95.3) having the following declaration std::basic_string<char,string_char_traits<char>,malloc_alloc> x; The header file was

#include <std/bastring.h>

Now, I am migrating to GU g++ 4.9 where I'm getting this error: 1. std/bastring.h not found 2. When I change #include <std/bastring.h> as #include <string>, I'm getting the following error:

error: 'string_char_traits' was not declared in this scope
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
error: template argument 2 is invalid
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
error: expected unqualified-id before ',' token
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
                                              ^

Need guidance / help to make this compilable under GNU g++ 4.9

like image 212
Dr. Debasish Jana Avatar asked Nov 08 '22 13:11

Dr. Debasish Jana


1 Answers

Despite the publication of ISO/IEC 14882:1998, GCC 2.95.3 is very much not a C++98 conforming compiler. We're talking about a 15 year old compiler running on the coattails of god awful who-knows-what non-standard code from the '90s. For one thing, here's a snippet from bastring.h:

// Written by Jason Merrill based upon the specification by Takanori Adachi
// in ANSI X3J16/94-0013R2.

...

// NOTE : This does NOT conform to the draft standard and is likely to change
#include <alloc.h>

I don't know what ANSI X3J16/94-0013R2 but it definitely has nothing to do with ISO C++98. malloc_alloc is found in alloc.h, if for some reason you want to explicitly want malloc and free to to be used in the allocator.

Anyways, your codebase is no doubt going to have to be rewritten from scratch. std::basic_string<char,string_char_traits<char>,malloc_alloc> x; can be replaced with std::string. But I shudder at the horrors of what other pre-standard code lies in there.

like image 122
uh oh somebody needs a pupper Avatar answered Nov 14 '22 23:11

uh oh somebody needs a pupper