Re: Using STL in a library interface
Ivan Vecerina wrote:
"carlosrf82" <carlosrf82@gmail.com> wrote in message
=BFis not STL a Standard Template Library?
I dont understand, if i'd want a API based on C++ and
export C++ Class =BFwhy could not i use C++ STL?
You can. But you may face problems because different
C++ platform may implement incompatible binary interfaces.
This is a platform specific issue: most operating systems
have a well-defined C binding interace -- which all compilers
and languages can adhere to.
It's not just that - there are also problems with heap management,
particularly if using a reference-counted implementation of
std::string.
I have a portable_string class (actually portable_basic_string
template) that actually is a bit like boost_array, has an implicit
constructor from a string and a non-implicit conversion back (you have
to call asString() to get a std::string back) and is reference-counted
for large strings. But because the destruction is done via a virtual
method of a deleter_base, it is safe. Originally this class was
intended to be very light so all you would do was create it, pass it
and then convert back to string locally. However in the end I
implemented most of the const methods on it. You cannot modify one
though other assigning it.
Now I said that my class uses something similar to boost_array. So you
will ask, why not just use boost_array? Because you might end up with
the same portability issues. First of all, not everybody has boost ,and
secondly there may possibly be different versions of boost_array
(someone uses a legacy version?).
Now, is all this a design flaw in C++? Should there be a C++ runtime
library?