|
|
Rivet 4.0.0
|
25#include <unordered_set>
44 struct has_const_iterator : private sfinae_base
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);
55 struct has_begin_end : private sfinae_base
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>
83 struct delimiters_values
85 using char_type = TChar;
86 const char_type * prefix;
87 const char_type * delimiter;
88 const char_type * postfix;
94 template < typename T, typename TChar>
97 using type = delimiters_values<TChar>;
98 static const type values;
106 template < typename T,
107 typename TChar = char,
108 typename TCharTraits = ::std::char_traits<TChar>,
109 typename TDelimiters = delimiters<T, TChar>>
110 struct print_container_helper
112 using delimiters_type = TDelimiters;
113 using ostream_type = std::basic_ostream<TChar, TCharTraits>;
115 template < typename U>
118 static void print_body( const U & c, ostream_type & stream)
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;
141 print_container_helper( const T & container)
142 : container_(container)
145 inline void operator()(ostream_type & stream) const
147 if (delimiters_type::values.prefix != NULL)
148 stream << delimiters_type::values.prefix;
150 printer<T>::print_body(container_, stream);
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>
164 struct print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<std::pair<T1, T2>>
166 using ostream_type = typename print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type;
168 static void print_body( const std::pair<T1, T2> & c, ostream_type & stream)
171 if (print_container_helper<T, TChar, TCharTraits, TDelimiters>::delimiters_type::values.delimiter != NULL)
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>
181 struct print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<std::tuple<Args...>>
183 using ostream_type = typename print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type;
184 using element_type = std::tuple<Args...>;
186 template <std:: size_t I> struct Int { };
188 static void print_body( const element_type & c, ostream_type & stream)
190 tuple_print(c, stream, Int<0>());
193 static void tuple_print( const element_type &, ostream_type &, Int< sizeof...(Args)>)
197 static void tuple_print( const element_type & c, ostream_type & stream,
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>
205 static void tuple_print( const element_type & c, ostream_type & stream, Int<N>)
207 if (print_container_helper<T, TChar, TCharTraits, TDelimiters>::delimiters_type::values.delimiter != NULL)
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>
219 inline std::basic_ostream<TChar, TCharTraits> & operator<<(
220 std::basic_ostream<TChar, TCharTraits> & stream,
221 const print_container_helper<T, TChar, TCharTraits, TDelimiters> & helper)
230 template < typename T>
231 struct is_container : public std::integral_constant<bool,
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>
237 struct is_container<T[N]> : std::true_type { };
239 template <std:: size_t N>
240 struct is_container<char[N]> : std::false_type { };
242 template < typename T>
243 struct is_container< std::valarray<T>> : std::true_type { };
245 template < typename T1, typename T2>
246 struct is_container< std::pair<T1, T2>> : std::true_type { };
248 template < typename ...Args>
249 struct is_container< std::tuple<Args...>> : std::true_type { };
254 template < typename T> struct delimiters<T, char> { static const delimiters_values<char> values; };
255 template < typename T> const delimiters_values<char> delimiters<T, char>::values = { "[", ", ", "]" };
256 template < typename T> struct delimiters<T, wchar_t> { static const delimiters_values<wchar_t> values; };
257 template < typename T> const delimiters_values<wchar_t> delimiters<T, wchar_t>::values = { L "[", L ", ", L "]" };
262 template < typename T, typename TComp, typename TAllocator>
263 struct delimiters< ::std::set<T, TComp, TAllocator>, char> { static const delimiters_values<char> values; };
265 template < typename T, typename TComp, typename TAllocator>
266 const delimiters_values<char> delimiters< ::std::set<T, TComp, TAllocator>, char>::values = { "{", ", ", "}" };
268 template < typename T, typename TComp, typename TAllocator>
269 struct delimiters< ::std::set<T, TComp, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
271 template < typename T, typename TComp, typename TAllocator>
272 const delimiters_values<wchar_t> delimiters< ::std::set<T, TComp, TAllocator>, wchar_t>::values = { L "{", L ", ", L "}" };
274 template < typename T, typename TComp, typename TAllocator>
275 struct delimiters< ::std::multiset<T, TComp, TAllocator>, char> { static const delimiters_values<char> values; };
277 template < typename T, typename TComp, typename TAllocator>
278 const delimiters_values<char> delimiters< ::std::multiset<T, TComp, TAllocator>, char>::values = { "{", ", ", "}" };
280 template < typename T, typename TComp, typename TAllocator>
281 struct delimiters< ::std::multiset<T, TComp, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
283 template < typename T, typename TComp, typename TAllocator>
284 const delimiters_values<wchar_t> delimiters< ::std::multiset<T, TComp, TAllocator>, wchar_t>::values = { L "{", L ", ", L "}" };
286 template < typename T, typename THash, typename TEqual, typename TAllocator>
287 struct delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, char> { static const delimiters_values<char> values; };
289 template < typename T, typename THash, typename TEqual, typename TAllocator>
290 const delimiters_values<char> delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, char>::values = { "{", ", ", "}" };
292 template < typename T, typename THash, typename TEqual, typename TAllocator>
293 struct delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
295 template < typename T, typename THash, typename TEqual, typename TAllocator>
296 const delimiters_values<wchar_t> delimiters< ::std::unordered_set<T, THash, TEqual, TAllocator>, wchar_t>::values = { L "{", L ", ", L "}" };
298 template < typename T, typename THash, typename TEqual, typename TAllocator>
299 struct delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, char> { static const delimiters_values<char> values; };
301 template < typename T, typename THash, typename TEqual, typename TAllocator>
302 const delimiters_values<char> delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, char>::values = { "{", ", ", "}" };
304 template < typename T, typename THash, typename TEqual, typename TAllocator>
305 struct delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, wchar_t> { static const delimiters_values<wchar_t> values; };
307 template < typename T, typename THash, typename TEqual, typename TAllocator>
308 const delimiters_values<wchar_t> delimiters< ::std::unordered_multiset<T, THash, TEqual, TAllocator>, wchar_t>::values = { L "{", L ", ", L "}" };
313 template < typename T1, typename T2> struct delimiters< std::pair<T1, T2>, char> { static const delimiters_values<char> values; };
314 template < typename T1, typename T2> const delimiters_values<char> delimiters<std::pair<T1, T2>, char>::values = { "(", ", ", ")" };
315 template < typename T1, typename T2> struct delimiters< ::std::pair<T1, T2>, wchar_t> { static const delimiters_values<wchar_t> values; };
316 template < typename T1, typename T2> const delimiters_values<wchar_t> delimiters< ::std::pair<T1, T2>, wchar_t>::values = { L "(", L ", ", L ")" };
318 template < typename ...Args> struct delimiters< std::tuple<Args...>, char> { static const delimiters_values<char> values; };
319 template < typename ...Args> const delimiters_values<char> delimiters<std::tuple<Args...>, char>::values = { "(", ", ", ")" };
320 template < typename ...Args> struct delimiters< ::std::tuple<Args...>, wchar_t> { static const delimiters_values<wchar_t> values; };
321 template < typename ...Args> const delimiters_values<wchar_t> delimiters< ::std::tuple<Args...>, wchar_t>::values = { L "(", L ", ", L ")" };
328 struct custom_delims_base
330 virtual ~custom_delims_base() { }
331 virtual std::ostream & stream(::std::ostream &) = 0;
332 virtual std::wostream & stream(::std::wostream &) = 0;
335 template < typename T, typename Delims>
336 struct custom_delims_wrapper : custom_delims_base
338 custom_delims_wrapper( const T & t_) : t(t_) { }
340 std::ostream & stream(std::ostream & s)
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>
358 custom_delims( const Container & c) : base(new custom_delims_wrapper<Container, Delims>(c)) { }
360 std::unique_ptr<custom_delims_base> base;
363 template < typename TChar, typename TCharTraits, typename Delims>
364 inline std::basic_ostream<TChar, TCharTraits> & operator<<(std::basic_ostream<TChar, TCharTraits> & s, const custom_delims<Delims> & p)
366 return p.base->stream(s);
374 struct array_wrapper_n
376 typedef const T * const_iterator;
377 typedef T value_type;
379 array_wrapper_n( const T * const a, size_t n) : _array(a), _n(n) { }
380 inline const_iterator begin() const { return _array; }
381 inline const_iterator end() const { return _array + _n; }
384 const T * const _array;
392 template < typename T>
393 struct bucket_print_wrapper
395 typedef typename T::const_local_iterator const_iterator;
396 typedef typename T::size_type size_type;
398 const_iterator begin() const
400 return m_map.cbegin(n);
403 const_iterator end() const
405 return m_map.cend(n);
408 bucket_print_wrapper( const T & m, size_type bucket) : m_map(m), n(bucket) { }
421inline pretty_print::array_wrapper_n<T> pretty_print_array( const T * const a, size_t n)
423 return pretty_print::array_wrapper_n<T>(a, n);
426template < typename T> pretty_print::bucket_print_wrapper<T>
427bucket_print( const T & m, typename T::size_type n)
429 return pretty_print::bucket_print_wrapper<T>(m, n);
444template< typename T, typename TChar, typename TCharTraits>
445inline typename enable_if< ::Rivet::pretty_print::is_container<T>::value,
446 basic_ostream<TChar, TCharTraits> &>::type
447operator<<(std::basic_ostream<TChar, TCharTraits> & stream, const T & container)
449 return stream << ::Rivet::pretty_print::print_container_helper<T, TChar, TCharTraits>(container);
Definition MC_CENT_PPB_Projections.hh:10
std::ostream & operator<<(std::ostream &os, const AnalysisInfo &ai) Stream an AnalysisInfo as a text description. Definition AnalysisInfo.hh:362
|