// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_TEMPLATE_UTIL_H_ #define BASE_TEMPLATE_UTIL_H_ #include #include #include #include #include "build/build_config.h" // This hacks around libstdc++ 4.6 missing stuff in type_traits, while we need // to support it. #define CR_GLIBCXX_4_7_0 20120322 #define CR_GLIBCXX_4_5_4 20120702 #define CR_GLIBCXX_4_6_4 20121127 #if defined(__GLIBCXX__) && \ (__GLIBCXX__ < CR_GLIBCXX_4_7_0 || __GLIBCXX__ == CR_GLIBCXX_4_5_4 || \ __GLIBCXX__ == CR_GLIBCXX_4_6_4) #define CR_USE_FALLBACKS_FOR_OLD_GLIBCXX #endif namespace base { template struct is_non_const_reference : std::false_type {}; template struct is_non_const_reference : std::true_type {}; template struct is_non_const_reference : std::false_type {}; // is_assignable namespace internal { template struct SelectSecond { using type = Second; }; struct Any { Any(...); }; // True case: If |Lvalue| can be assigned to from |Rvalue|, then the return // value is a true_type. template typename internal::SelectSecond< decltype((std::declval() = std::declval())), std::true_type>::type IsAssignableTest(Lvalue&&, Rvalue&&); // False case: Otherwise the return value is a false_type. template std::false_type IsAssignableTest(internal::Any, Rvalue&&); // Default case: Neither Lvalue nor Rvalue is void. Uses IsAssignableTest to // determine the type of IsAssignableImpl. template ::value || std::is_void::value> struct IsAssignableImpl : public std::common_type(), std::declval()))>::type {}; // Void case: Either Lvalue or Rvalue is void. Then the type of IsAssignableTest // is false_type. template struct IsAssignableImpl : public std::false_type {}; // Uses expression SFINAE to detect whether using operator<< would work. template struct SupportsOstreamOperator : std::false_type {}; template struct SupportsOstreamOperator() << std::declval()))> : std::true_type {}; } // namespace internal // TODO(crbug.com/554293): Remove this when all platforms have this in the std // namespace. template struct is_assignable : public internal::IsAssignableImpl {}; // is_copy_assignable is true if a T const& is assignable to a T&. // TODO(crbug.com/554293): Remove this when all platforms have this in the std // namespace. template struct is_copy_assignable : public is_assignable::type, typename std::add_lvalue_reference< typename std::add_const::type>::type> {}; // is_move_assignable is true if a T&& is assignable to a T&. // TODO(crbug.com/554293): Remove this when all platforms have this in the std // namespace. template struct is_move_assignable : public is_assignable::type, const typename std::add_rvalue_reference::type> { }; // underlying_type produces the integer type backing an enum type. // TODO(crbug.com/554293): Remove this when all platforms have this in the std // namespace. #if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX) template struct underlying_type { using type = __underlying_type(T); }; #else template using underlying_type = std::underlying_type; #endif // TODO(crbug.com/554293): Remove this when all platforms have this in the std // namespace. #if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX) template using is_trivially_destructible = std::has_trivial_destructor; #else template using is_trivially_destructible = std::is_trivially_destructible; #endif } // namespace base #undef CR_USE_FALLBACKS_FOR_OLD_GLIBCXX #endif // BASE_TEMPLATE_UTIL_H_