Support Class Library
A set of tools providing classes and utility
prefixed.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <iostream>
5 #include <functional>
7 #include <scl/macros.h>
8 
9 namespace scl{
10  namespace tools{
11  namespace iostream{
12  namespace log{
17  namespace prefixed{
24  template <class T=std::string>
25  inline std::function<decltype(std::cout)&(const T&)> log(realConst(char*) prefix){
26  decltype(std::cout)* cout = &std::cout;
27  return [=](const T& value) -> decltype(std::cout)&{
28  return (*cout) << prefix << value << nl;
29  };
30  }
31 
38  template <class T=std::string>
39  inline std::function<decltype(std::cerr)&(const T&)> error(realConst(char*) prefix){
40  decltype(std::cerr)* cerr = &std::cerr;
41  return [=](const T& value) -> decltype(std::cerr)&{
42  return (*cerr) << prefix << value << nl;
43  };
44  }
45  }
46  }
47  }
48  }
49 }
Global namespace of the SCL.
Definition: alias.hpp:3
#define realConst(type)
Definition: macros.h:3
std::function< decltype(std::cout)&(const T &)> log(const char *const prefix)
Log for the given type on stdout w/ a prefix and end with a line break.
Definition: prefixed.h:25
std::basic_ostream< Char, Traits > & nl(std::basic_ostream< Char, Traits > &os)
An alternative for std::endl that actually does what you assumed std::endl was doing.
Definition: nl.h:14
std::function< decltype(std::cerr)&(const T &)> error(const char *const prefix)
Log for the given type on stderr w/ a prefix and end with a line break.
Definition: prefixed.h:39