Alexei Novakov wrote:
Cool, I'd definitely use it"Vincent Finn" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...Forwarded to main Boost list - that's the more appropriate venue for discussions of possible additions. -- Jim Hyslop boost-users moderator. > -----Original Message----- > From: alexei_novakov [mailto:[EMAIL PROTECTED]] > Sent: Monday, November 18, 2002 7:05 PM > To: [EMAIL PROTECTED] > Subject: [Boost-Users] Possible boost addition: sub string and const > string. > > > Hello everyone. > > I have two classes which I found pretty handy: sub_string (behaves as > a mirror of the portion of master basic_string) and const_string (C- > string wrapper). Nice thing about these two is they implemented as > template specialization of basic_string which has advantages: > a) familiar interface; > b) possibility to reuse the code written for basic_string (like > string streams, lexical casts, etc). > > Any interest? > > Regards. > > Alexei Novakov Sounds interesting, like slice on a valarray When I have to do a lot of manipulation of sub string and can't afford to copy back and forward I normally resort to using vector<char>; this sounds a lot handier How does it work ? VinThe idea is simple. Sub string is declared as basic_string template specialization: template <typename CHAR, typename TRAITS, typename ALLOCATOR> class basic_string<CHAR, TRAITS, basic_string<CHAR, TRAITS, ALLOCATOR> > The interfase is the same as for basic_string (except constructors). Sub string instances contain reference to master string and boundaries (start and size). One can use it like this: // Start typedef basic_string<string::value_type, string::traits_type, string> sub_string; string str("1234567890"); sub_string ss(str, 2, 5); // master string, start position, size assert(lexical_cast<int>(ss) == 34567); ss = "$$"; assert(str == "12$$890"); // End All the basic_string operators (like +, ==, !=, <, >, <=, >=) are overloaded to be used for both strings and sub strings. Similar approach is used for const_string (C string wrapper), but only const methods of basic_string are implemented. Alexei.
Seeing as there is a move to submit a library of string helpers at the moment it might be worth submitting this at the same time!
Vin
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost