1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEMPLATE_UTIL_H_ 6 #define BASE_TEMPLATE_UTIL_H_ 7 8 #include <iosfwd> 9 #include <iterator> 10 #include <type_traits> 11 #include <utility> 12 13 namespace base { 14 15 namespace internal { 16 17 // Uses expression SFINAE to detect whether using operator<< would work. 18 template <typename T, typename = void> 19 struct SupportsOstreamOperator : std::false_type {}; 20 template <typename T> 21 struct SupportsOstreamOperator<T, 22 decltype(void(std::declval<std::ostream&>() 23 << std::declval<T>()))> 24 : std::true_type {}; 25 26 // Used to detech whether the given type is an iterator. This is normally used 27 // with std::enable_if to provide disambiguation for functions that take 28 // templatzed iterators as input. 29 template <typename T, typename = void> 30 struct is_iterator : std::false_type {}; 31 32 template <typename T> 33 struct is_iterator< 34 T, 35 std::void_t<typename std::iterator_traits<T>::iterator_category>> 36 : std::true_type {}; 37 38 } // namespace internal 39 40 } // namespace base 41 42 #endif // BASE_TEMPLATE_UTIL_H_ 43