tlx
tuple.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/logger/tuple.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2018 Timo Bingmann <tb@panthema.net>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_LOGGER_TUPLE_HEADER
12 #define TLX_LOGGER_TUPLE_HEADER
13 
14 #include <tlx/logger/core.hpp>
16 
17 #include <tuple>
18 
19 namespace tlx {
20 
22 {
23 public:
24  explicit LoggerTupleFormatter(std::ostream& os) : os_(os) { }
25  template <typename Index, typename Arg>
26  void operator () (const Index&, const Arg& a) const {
27  if (Index::index != 0) os_ << ',';
29  }
30  std::ostream& os_;
31 };
32 
33 template <typename... Args>
34 class LoggerFormatter<std::tuple<Args...> >
35 {
36 public:
37  static void print(std::ostream& os, const std::tuple<Args...>& t) {
38  os << '(';
40  os << ')';
41  }
42 };
43 
44 template <>
45 class LoggerFormatter<std::tuple<> >
46 {
47 public:
48  static void print(std::ostream& os, const std::tuple<>&) {
49  os << '(' << ')';
50  }
51 };
52 
53 } // namespace tlx
54 
55 #endif // !TLX_LOGGER_TUPLE_HEADER
56 
57 /******************************************************************************/
void call_foreach_tuple_with_index(Functor &&f, Tuple &&t)
Call a generic functor (like a generic lambda) to each components of a tuple together with its zero-b...
static void print(std::ostream &os, const std::tuple< Args... > &t)
Definition: tuple.hpp:37
STL namespace.
std::ostream & os_
Definition: tuple.hpp:30
void operator()(const Index &, const Arg &a) const
Definition: tuple.hpp:26
template class for formatting. contains a print() method.
Definition: core.hpp:25
static void print(std::ostream &os, const std::tuple<> &)
Definition: tuple.hpp:48
LoggerTupleFormatter(std::ostream &os)
Definition: tuple.hpp:24