All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
print_collection.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
16 #ifndef PAAL_PRINT_COLLECTION_HPP
17 #define PAAL_PRINT_COLLECTION_HPP
18 
19 #include <boost/range/empty.hpp>
20 #include <boost/range.hpp>
21 
22 namespace paal {
23 
33 template <typename Range, typename Stream>
34 void print_collection(Stream &o, Range &&r, const std::string &del) {
35  auto b = std::begin(r);
36  auto e = std::end(r);
37  if (b == e) {
38  return;
39  }
40  o << *b;
41  for (auto &&x : boost::make_iterator_range(++b, e)) {
42  o << del << x;
43  }
44 }
45 
55 template <typename Matrix, typename Stream>
56 void print_matrix(Stream &o, Matrix &&m, const std::string &del) {
57  auto b = m.begin1();
58  auto e = m.end1();
59  if (b == e) {
60  return;
61  }
62  print_collection(o, b, del);
63  for (++b ;b != e; ++b) {
64  o << std::endl;
65  print_collection(o, b, del);
66  }
67 }
68 
69 }
70 
71 #endif // PAAL_PRINT_COLLECTION_HPP
void print_matrix(Stream &o, Matrix &&m, const std::string &del)
prints matrix with delimiters
void print_collection(Stream &o, Range &&r, const std::string &del)
prints collection with delimiters without trailing delimiter