Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2002-08-30 10:49:32


From: Carlo Wood <carlo_at_[hidden]>
> On Fri, Aug 30, 2002 at 03:54:03PM -0400, Toon Knapen wrote:
> > why not
> > void demangle(std::string& o, const std::type_info& i)
> > to avoid the C-style argument overloading.
>
> Because typeid().name() returns a 'char const*'.
> It makes no sense to force people to first copy
> that into a string before they can demangle it.

Your interface and implementation don't need to use the same
parameter types. For example, you could implement
boost::details::demangle() to take a char const *, while
boost::demangle() takes std::basic_strings (suitably
parameterized) and std::type_infos.

> We can always provide a wrapper, given a std::string,
> that passes the data to the demangler.

Right, but the "wrapper" could be the only version exposed.

> Perhaps the best interface for the most general one
> is to make the library accept both, zero terminated
> input as well as a given length. Then we can pass
> a C style string but also a std::string directly
> (without the need for a copy) by passing its length.

details::demangle() could take a char const * and a size_t
instead of just the former to make it fully generalized.

> I hate copying strings :)

Given that your demangling logic will be invoked in almost every
use case strictly for error reporting, performance is not an
issue. Therefore, any performance concern wrt copying strings is
moot.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk