|
Boost Users : |
Subject: Re: [Boost-users] [Ranges] make_view: when will it be part of a release?
From: Chris Hoeppler (hoeppler_at_[hidden])
Date: 2009-01-11 11:25:34
On Sunday 11 January 2009, Christoph Duelli wrote:
> I recently had the need to produce from a vector<uint> a string
> representation (like for IPs) like "23.1.4.742.234.0".
You could also use Karma (part of the Spirit 2 library) for that job.
See the included example.
HTH,
Chris
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/spirit/include/karma.hpp>
#include <cassert>
#include <cstdlib>
#include <vector>
using namespace boost::assign; // bring 'operator+=()' into scope
using namespace boost::spirit;
using namespace boost::spirit::ascii;
int main()
{
std::vector<int> v;
v += 23, 1, 4, 742, 234, 0;
std::string generated;
bool success = karma::generate(std::back_inserter(generated),
int_ % ".", // format description
v // data
);
assert(success && "23.1.4.742.234.0" == generated);
return EXIT_SUCCESS;
}
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