Not pretty, but working:
#include <iostream>
#include <iterator>
#include <vector>
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include "boost/spirit/include/karma.hpp"
#include <boost/spirit/include/phoenix.hpp>
namespace karma = boost::spirit::karma;
namespace phx = boost::phoenix;
typedef std::back_insert_iterator<std::string> BackInsertIt;
int main(int argc, char* argv[]) {
std::vector<float> input;
input.push_back(1.0f);
input.push_back(2.0f);
struct TestGram: karma::grammar<BackInsertIt, std::vector<float>(),
karma::space_type> {
TestGram()
: TestGram::base_type(output) {
using namespace karma;
floatRule = double_;
output = repeat(phx::bind(&std::vector<float>::size, (karma::_val)))[floatRule]
<< repeat(3 - phx::bind(&std::vector<float>::size, (karma::_val)))[karma::lit("0.0")];
}
karma::rule<BackInsertIt, std::vector<float>(), karma::space_type> output;
karma::rule<BackInsertIt, float(), karma::space_type> floatRule;
} testGram;
std::string output;
BackInsertIt sink(output);
karma::generate_delimited(sink, testGram, karma::space, input);
std::cout << "Generated: " << output << std::endl;
return 0;
}