prettyprint.hpp
27 // Pre-declarations of container types so we don't actually have to include the relevant headers if not needed, speeding up compilation time.
31 template<typename T, typename THash, typename TEqual, typename TAllocator> class unordered_multiset;
95 // Basic is_container template; specialize to derive from std::true_type for all desired container types
129 template<typename T> struct delimiters<T, char> { static const delimiters_values<char> values; };
130 template<typename T> const delimiters_values<char> delimiters<T, char>::values = { "[", ", ", "]" };
131 template<typename T> struct delimiters<T, wchar_t> { static const delimiters_values<wchar_t> values; };
132 template<typename T> const delimiters_values<wchar_t> delimiters<T, wchar_t>::values = { L"[", L", ", L"]" };
138 struct delimiters< ::std::set<T, TTraits, TAllocator>, char> { static const delimiters_values<char> values; };
141 const delimiters_values<char> delimiters< ::std::set<T, TTraits, TAllocator>, char>::values = { "{", ", ", "}" };
144 struct delimiters< ::std::set<T, TTraits, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
147 const delimiters_values<wchar_t> delimiters< ::std::set<T, TTraits, TAllocator>, wchar_t>::values = { L"{", L", ", L"}" };
150 struct delimiters< ::std::multiset<T, TTraits, TAllocator>, char> { static const delimiters_values<char> values; };
153 const delimiters_values<char> delimiters< ::std::multiset<T, TTraits, TAllocator>, char>::values = { "{", ", ", "}" };
156 struct delimiters< ::std::multiset<T, TTraits, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
159 const delimiters_values<wchar_t> delimiters< ::std::multiset<T, TTraits, TAllocator>, wchar_t>::values = { L"{", L", ", L"}" };
162 struct delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, char> { static const delimiters_values<char> values; };
165 const delimiters_values<char> delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, char>::values = { "{", ", ", "}" };
168 struct delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
171 const delimiters_values<wchar_t> delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, wchar_t>::values = { L"{", L", ", L"}" };
174 struct delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, char> { static const delimiters_values<char> values; };
177 const delimiters_values<char> delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, char>::values = { "{", ", ", "}" };
180 struct delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
183 const delimiters_values<wchar_t> delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, wchar_t>::values = { L"{", L", ", L"}" };
188 template<typename T1, typename T2> struct delimiters< ::std::pair<T1, T2>, char> { static const delimiters_values<char> values; };
189 template<typename T1, typename T2> const delimiters_values<char> delimiters< ::std::pair<T1, T2>, char>::values = { "(", ", ", ")" };
190 template<typename T1, typename T2> struct delimiters< ::std::pair<T1, T2>, wchar_t> { static const delimiters_values<wchar_t> values; };
191 template<typename T1, typename T2> const delimiters_values<wchar_t> delimiters< ::std::pair<T1, T2>, wchar_t>::values = { L"(", L", ", L")" };
200 // Functor to print containers. You can use this directly if you want to specificy a non-default delimiters type.
202 template<typename T, typename TChar = char, typename TCharTraits = ::std::char_traits<TChar>, typename TDelimiters = delimiters<T, TChar>>
241 // Requires TCharTraits = std::char_traits<TChar> and TChar = char or wchar_t, and MyDelims needs to be defined for TChar.
258 return stream << ::pretty_print::print_container_helper<T, char, ::std::char_traits<char>, Delims>(t);
262 return stream << ::pretty_print::print_container_helper<T, wchar_t, ::std::char_traits<wchar_t>, Delims>(t);
272 template<typename Container> custom_delims(const Container & c) : base(new custom_delims_wrapper<Container, Delims>(c)) { }
281 inline std::basic_ostream<TChar, TCharTraits> & operator<<(std::basic_ostream<TChar, TCharTraits> & stream, const pretty_print::custom_delims<Delims> & p)
290 // Implement as "template<T, C, A> const sdelims::type sdelims<std::set<T,C,A>>::values = { ... }."
301 inline basic_ostream<TChar, TCharTraits> & operator<<(basic_ostream<TChar, TCharTraits> & stream,
311 inline typename enable_if< ::pretty_print::is_container<T>::value, basic_ostream<TChar, TCharTraits>&>::type
319 inline basic_ostream<TChar, TCharTraits> & operator<<(basic_ostream<TChar, TCharTraits> & stream, const pair<T1, T2> & value)
338 // Prints a tuple to the stream using delimiters from delimiters<std::pair<tuple_dummy_t, tuple_dummy_t>>.
349 static inline void print(::std::basic_ostream<TChar, TCharTraits> & stream, const Tuple & value)
363 static inline void print(::std::basic_ostream<TChar, TCharTraits> & stream, const Tuple & value)
373 * Credits to STL: http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-6-of-n
390 inline basic_ostream<TChar, TCharTraits> & operator<<(basic_ostream<TChar, TCharTraits> & stream, const tuple<TUPLE_ARGS> & value)
392 if (::pretty_print::delimiters< ::pretty_print::tuple_dummy_pair, TChar>::values.prefix != NULL)
395 ::pretty_print::pretty_tuple_helper<const tuple<TUPLE_ARGS> &, tuple_size<tuple<TUPLE_ARGS>>::value, TChar, TCharTraits>::print(stream, value);
397 if (::pretty_print::delimiters< ::pretty_print::tuple_dummy_pair, TChar>::values.postfix != NULL)
407 inline basic_ostream<TChar, TCharTraits> & operator<<(basic_ostream<TChar, TCharTraits> & stream, class function<_Res(_ArgTypes...)> func)
413 // A wrapper for raw C-style arrays. Usage: int arr[] = { 1, 2, 4, 8, 16 }; std::cout << wrap_array(arr) << ...
Definition: prettyprint.hpp:34
Definition: prettyprint.hpp:244
Definition: prettyprint.hpp:342
Definition: prettyprint.hpp:196
Definition: prettyprint.hpp:62
Definition: prettyprint.hpp:77
Definition: prettyprint.hpp:30
Definition: prettyprint.hpp:120
Definition: prettyprint.hpp:108
Definition: prettyprint.hpp:25
Definition: prettyprint.hpp:270
Definition: prettyprint.hpp:97
Definition: prettyprint.hpp:29
Definition: prettyprint.hpp:347
Definition: prettyprint.hpp:56
Definition: prettyprint.hpp:203
Definition: prettyprint.hpp:65
Definition: prettyprint.hpp:40
Definition: prettyprint.hpp:31
Definition: prettyprint.hpp:63
Definition: prettyprint.hpp:418
Definition: prettyprint.hpp:252
Definition: prettyprint.hpp:58
Definition: prettyprint.hpp:28
Generated by Doxygen 1.8.11