|
Boost Users : |
Subject: Re: [Boost-users] [uuid] to string problem
From: Andy Tompkins (atompkins_at_[hidden])
Date: 2010-05-11 09:00:33
< snip >
> >>
> >> string GeneratorUtils::getRandomID()
> >> {
> >>
> >> random_generator gen;
> >> uuid u = gen();
> >>
> >> return u.uuid_to_string(); // ERROR
> >> }
> >>
> >> It does not accept any to_string() function. Is there a way to
> >> convert from uuid to string in C++? (by the way, I can use the
> >> other things such as date d, uuid u etc.)
> >
> > see
> > http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#boost/uuid/uuid_io.hpp
> >
> > one can also use lexical_cast eg:
> > uuid u;
> > string s = lexical_cast<string>(u);
> >
> > I'll update the documentation to include this example.
>
> By the way. Andy, do you plan to implement to_string() member-function
> or standalone function? AFAIK lexical_cast has a lot of overhead :(
Hmm, I haven't really given it much thought. Since it doesn't need to
be a member function, I would lean toward a standalone function. Do
any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A>
std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u);
std::wstring to_wstring(boost::uuids::uuid conts& u);
Regards,
Andy.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net