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 
21 class LoggerTupleFormatter
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_ << ',';
28  LoggerFormatter<typename std::decay<Arg>::type>::print(os_, a);
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 << '(';
39  call_foreach_tuple_with_index(LoggerTupleFormatter(os), t);
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 /******************************************************************************/
tlx::LoggerTupleFormatter::os_
std::ostream & os_
Definition: tuple.hpp:46
tlx::LoggerFormatter
template class for formatting. contains a print() method.
Definition: core.hpp:35
tlx::call_foreach_tuple_with_index
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...
Definition: call_foreach_tuple_with_index.hpp:53
tlx::LoggerTupleFormatter::operator()
void operator()(const Index &, const Arg &a) const
Definition: tuple.hpp:42
tlx
Definition: exclusive_scan.hpp:17
tlx::LoggerTupleFormatter::LoggerTupleFormatter
LoggerTupleFormatter(std::ostream &os)
Definition: tuple.hpp:40
call_foreach_tuple_with_index.hpp
core.hpp