Support Class Library
A set of tools providing classes and utility
surrounded.h
Go to the documentation of this file.
1 #pragma once
2 
3 #pragma once
4 
5 #include <string>
6 #include <iostream>
7 #include <functional>
9 #include <scl/macros.h>
10 
11 namespace scl{
12  namespace tools{
13  namespace iostream{
14  namespace log{
19  namespace surrounded{
27  template <class T=std::string>
28  inline std::function<decltype(std::cout)&(const T&)> log(realConst(char*) prefix, realConst(char*) suffix){
29  decltype(std::cout)* cout = &std::cout;
30  return [=](const T& value) -> decltype(std::cout)&{
31  return (*cout) << prefix << value << suffix << nl;
32  };
33  }
34 
42  template <class T=std::string>
43  inline std::function<decltype(std::cerr)&(const T&)> error(realConst(char*) prefix, realConst(char*) suffix){
44  decltype(std::cerr)* cerr = &std::cerr;
45  return [=](const T& value) -> decltype(std::cerr)&{
46  return (*cerr) << prefix << value << suffix << nl;
47  };
48  }
49  }
50  }
51  }
52  }
53 }
Global namespace of the SCL.
Definition: alias.hpp:3
#define realConst(type)
Definition: macros.h:3
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::cout)&(const T &)> log(const char *const prefix, const char *const suffix)
Log on stdout with a prefix and a suffix, end with a line break.
Definition: surrounded.h:28
std::function< decltype(std::cerr)&(const T &)> error(const char *const prefix, const char *const suffix)
Log on stderr with a prefix and a suffix, end with a line break.
Definition: surrounded.h:43