1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
#ifndef CSV_PRINTER_HPP
#define CSV_PRINTER_HPP

#include <iostream>
#include <utility>

namespace print_csv_line_impl {

   template<typename Arg>
   bool print_csv_args(std::ostream& out, Arg&& arg) {
      out << "," << arg;
      return !!out;
   }

   template<typename Arg, typename... Args>
   bool print_csv_args(std::ostream& out, Arg&& arg, Args&&... args) {
      return print_csv_args(out, arg) &&
	 print_csv_args(out, std::forward<Args>(args)...);
   }
} // namespace print_csv_line_impl

template<typename Arg, typename... Args>
bool print_csv_line(std::ostream& out, Arg&& arg, Args&&... args) {
   if (out << arg &&
	 print_csv_line_impl::print_csv_args(out,
	    std::forward<Args>(args)...)) {
      out << std::endl;
   }
   return !!out;
}

#endif