This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::string and literals



Q. Is there a way to specifically create a std::string instance that will
just be a reference to the given literal? (with copy on write semantics
of course).

No. a 'string' is an object and naturally manages its own state.

In my private tool box I have a class called basic_stringref
(with the obvious typedef basic_stringref<char> stringref).
It does what you want - wraps a 'string' facade around an
existing character array without making a copy. Of course,
it is not a 'string' and so can not be passed to a function that
expects one. If you are interested in more details email me directly.

Jack

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]