PageRenderTime 39ms CodeModel.GetById 16ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/prelude/delimited_ostream.hpp

http://github.com/Eelis/geordi
C++ Header | 48 lines | 36 code | 12 blank | 0 comment | 1 complexity | 4c5cec86435f94bbb17e228e837918ac MD5 | raw file
 1#ifndef DELIMITED_OSTREAM_HPP
 2#define DELIMITED_OSTREAM_HPP
 3
 4#include <iostream>
 5#include <ios>
 6
 7#if __cplusplus >= 201103
 8
 9#include <type_traits>
10
11namespace del_ostream_detail
12{
13  template<typename T> constexpr bool take_by_value()
14  { return std::is_integral<T>::value || std::is_enum<T>::value; }
15}
16
17template <typename Ch, typename Tr, typename T>
18inline typename std::enable_if<
19    !del_ostream_detail::take_by_value<T>(),
20    std::basic_ostream<Ch, Tr> >::type &
21  operator,(std::basic_ostream<Ch, Tr> & o, T const & t)
22{ return o << ", " << t; }
23
24template <typename Ch, typename Tr, typename T>
25inline typename std::enable_if<
26    del_ostream_detail::take_by_value<T>(),
27    std::basic_ostream<Ch, Tr> >::type &
28  operator,(std::basic_ostream<Ch, Tr> & o, T const t)
29{ return o << ", " << t; }
30
31#else
32
33template <typename Ch, typename Tr, typename T>
34inline std::basic_ostream<Ch, Tr> &
35  operator,(std::basic_ostream<Ch, Tr> & o, T const & t)
36{ return o << ", " << t; }
37
38#endif
39
40template <typename Ch, typename Tr>
41std::basic_ostream<Ch, Tr> & operator, (std::basic_ostream<Ch, Tr> & o, std::ios_base & (* const f) (std::ios_base &))
42{ return o << f; }
43
44template <typename Ch, typename Tr>
45std::basic_ostream<Ch, Tr> & operator, (std::basic_ostream<Ch, Tr> & o, std::basic_ostream<Ch, Tr> & (* const f) (std::basic_ostream<Ch, Tr> &))
46{ return o << f; }
47
48#endif // header guard