17 #ifndef H_PRETTY_PRINT
18 #define H_PRETTY_PRINT
26 #include <type_traits>
27 #include <unordered_set>
47 template <
typename C>
static yes & test(
typename C::const_iterator*);
48 template <
typename C>
static no & test(...);
50 static const bool value =
sizeof(test<T>(
nullptr)) ==
sizeof(
yes);
59 static yes & f(
typename std::enable_if<
60 std::is_same<decltype(
static_cast<typename C::const_iterator(C::*)() const
>(&C::begin)),
61 typename C::const_iterator(C::*)()
const>::
value>::type *);
63 template <
typename C>
static no & f(...);
66 static yes & g(
typename std::enable_if<
67 std::is_same<decltype(
static_cast<typename C::const_iterator(C::*)() const
>(&C::end)),
68 typename C::const_iterator(C::*)()
const>::
value,
void>::type*);
70 template <
typename C>
static no & g(...);
73 static bool const beg_value =
sizeof(f<T>(
nullptr)) ==
sizeof(
yes);
74 static bool const end_value =
sizeof(g<T>(
nullptr)) ==
sizeof(
yes);
82 template <
typename TChar>
94 template <
typename T,
typename TChar>
106 template <
typename T,
107 typename TChar = char,
108 typename TCharTraits = ::std::char_traits<TChar>,
115 template <
typename U>
124 const auto the_end = end(
c);
132 if (++it == the_end)
break;
134 if (delimiters_type::values.delimiter != NULL)
135 stream << delimiters_type::values.delimiter;
142 : container_(container)
147 if (delimiters_type::values.prefix != NULL)
148 stream << delimiters_type::values.prefix;
152 if (delimiters_type::values.postfix != NULL)
153 stream << delimiters_type::values.postfix;
157 const T & container_;
162 template <
typename T,
typename TChar,
typename TCharTraits,
typename TDelimiters>
163 template <
typename T1,
typename T2>
172 stream << print_container_helper<T, TChar, TCharTraits, TDelimiters>::delimiters_type::values.delimiter;
179 template <
typename T,
typename TChar,
typename TCharTraits,
typename TDelimiters>
180 template <
typename ...Args>
186 template <std::
size_t I>
struct Int { };
190 tuple_print(
c, stream, Int<0>());
198 typename std::conditional<
sizeof...(Args) != 0, Int<0>, std::nullptr_t>::type)
200 stream << std::get<0>(
c);
201 tuple_print(
c, stream, Int<1>());
204 template <std::
size_t N>
208 stream << print_container_helper<T, TChar, TCharTraits, TDelimiters>::delimiters_type::values.delimiter;
210 stream << std::get<N>(
c);
212 tuple_print(
c, stream, Int<N + 1>());
218 template<
typename T,
typename TChar,
typename TCharTraits,
typename TDelimiters>
220 std::basic_ostream<TChar, TCharTraits> & stream,
230 template <
typename T>
232 detail::has_const_iterator<T>::value &&
233 detail::has_begin_end<T>::beg_value &&
234 detail::has_begin_end<T>::end_value> { };
236 template <
typename T, std::
size_t N>
239 template <std::
size_t N>
242 template <
typename T>
245 template <
typename T1,
typename T2>
248 template <
typename ...Args>
262 template <
typename T,
typename TComp,
typename TAllocator>
265 template <
typename T,
typename TComp,
typename TAllocator>
268 template <
typename T,
typename TComp,
typename TAllocator>
271 template <
typename T,
typename TComp,
typename TAllocator>
274 template <
typename T,
typename TComp,
typename TAllocator>
277 template <
typename T,
typename TComp,
typename TAllocator>
280 template <
typename T,
typename TComp,
typename TAllocator>
283 template <
typename T,
typename TComp,
typename TAllocator>
286 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
289 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
292 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
295 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
298 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
301 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
304 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
307 template <
typename T,
typename THash,
typename TEqual,
typename TAllocator>
331 virtual std::ostream &
stream(::std::ostream &) = 0;
332 virtual std::wostream &
stream(::std::wostream &) = 0;
335 template <
typename T,
typename Delims>
342 return s << print_container_helper<T, char, std::char_traits<char>, Delims>(t);
345 std::wostream &
stream(std::wostream & s)
347 return s << print_container_helper<T, wchar_t, std::char_traits<wchar_t>, Delims>(t);
354 template <
typename Delims>
357 template <
typename Container>
360 std::unique_ptr<custom_delims_base>
base;
363 template <
typename TChar,
typename TCharTraits,
typename Delims>
366 return p.
base->stream(s);
384 const T *
const _array;
392 template <
typename T>
400 return m_map.cbegin(n);
405 return m_map.cend(n);
440 template<
typename T,
typename TChar,
typename TCharTraits>
442 basic_ostream<TChar, TCharTraits> &>::type
443 operator<<(basic_ostream<TChar, TCharTraits> & stream,
const T & container)
445 return stream << ::pretty_print::print_container_helper<T, TChar, TCharTraits>(container);
451 #endif // H_PRETTY_PRINT