Boost logo

Boost :

From: Oleg Abrosimov (beholder_at_[hidden])
Date: 2006-06-10 12:43:40


Hello dear authors of boost tuple libraries!

I've a need to implement a function that gets a tuple of manipulators
and applies them to stream:

template <typename T, typename Tuple>
std::string string_from(T const& t, Tuple const& manip)
{
     std::stringstream ss;
     ss << manip << t;
     return ss.str();
}

usage of this function would be:

std::string s = string_from(1.2, boost::make_tuple(std::setprecision(2),
std::scientific));

The problem is: how I can efficiently suppress output of
left/right/delimiter strings?
Of cause, with fusion::tuple I can do the following (manipulator names
are taken from boost::tuple docs, though):

template <typename T, typename Tuple>
std::string string_from(T const& t, Tuple const& manip)
{
     std::stringstream ss;
     ss << set_open("") << set_close("") << set_delimiter("") << manip << t;
     return ss.str();
}

but it has a lot of overhead in tuple's output iterator that should be
avoided for me.

I feel that the best solution would be to have a function
"print_tuple(stream, tuple)" in tuples library that just do what I want.

One more issue with fusion::tuple manipulators as they are in boost
1.33.1 (unofficially): I've discovered that only narrow strings and
characters are supported. am I right? If so, I believe that wide
versions should be added too.

Best regards,
Oleg Abrosimov.


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