123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- #ifndef BASE_TEMPLATE_UTIL_H_
- #define BASE_TEMPLATE_UTIL_H_
- #include <stddef.h>
- #include <iosfwd>
- #include <iterator>
- #include <type_traits>
- #include <utility>
- #include <vector>
- #include "build/build_config.h"
- #define CR_GLIBCXX_5_0_0 20150123
- #if (defined(__GNUC__) && __GNUC__ < 5) || \
- (defined(__GLIBCXX__) && __GLIBCXX__ == CR_GLIBCXX_5_0_0)
- #define CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX
- #endif
- #if !defined(__clang__) && defined(_LIBCPP_VERSION)
- #define CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX
- #endif
- namespace base {
- template <class T> struct is_non_const_reference : std::false_type {};
- template <class T> struct is_non_const_reference<T&> : std::true_type {};
- template <class T> struct is_non_const_reference<const T&> : std::false_type {};
- namespace internal {
- template <typename...>
- struct make_void {
- using type = void;
- };
- }
- template <typename... Ts>
- using void_t = typename ::base::internal::make_void<Ts...>::type;
- namespace internal {
- template <typename T, typename = void>
- struct SupportsOstreamOperator : std::false_type {};
- template <typename T>
- struct SupportsOstreamOperator<T,
- decltype(void(std::declval<std::ostream&>()
- << std::declval<T>()))>
- : std::true_type {};
- template <typename T, typename = void>
- struct SupportsToString : std::false_type {};
- template <typename T>
- struct SupportsToString<T, decltype(void(std::declval<T>().ToString()))>
- : std::true_type {};
- template <typename T, typename = void>
- struct is_iterator : std::false_type {};
- template <typename T>
- struct is_iterator<T,
- void_t<typename std::iterator_traits<T>::iterator_category>>
- : std::true_type {};
- template <size_t I>
- struct priority_tag : priority_tag<I - 1> {};
- template <>
- struct priority_tag<0> {};
- }
- #if defined(CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX) || \
- defined(CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX)
- template <typename T>
- struct is_trivially_copyable {
- #if _GNUC_VER >= 501
- static constexpr bool value = __is_trivially_copyable(T);
- #else
- static constexpr bool value =
- __has_trivial_copy(T) && __has_trivial_destructor(T);
- #endif
- };
- #else
- template <class T>
- using is_trivially_copyable = std::is_trivially_copyable<T>;
- #endif
- #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 7
- template <typename T>
- struct is_trivially_copy_constructible
- : std::is_trivially_copy_constructible<T> {};
- template <typename... T>
- struct is_trivially_copy_constructible<std::vector<T...>> : std::false_type {};
- #else
- template <typename T>
- using is_trivially_copy_constructible = std::is_trivially_copy_constructible<T>;
- #endif
- struct in_place_t {};
- constexpr in_place_t in_place = {};
- template <typename T>
- struct in_place_type_t {};
- template <typename T>
- struct is_in_place_type_t {
- static constexpr bool value = false;
- };
- template <typename... Ts>
- struct is_in_place_type_t<in_place_type_t<Ts...>> {
- static constexpr bool value = true;
- };
- template <bool B>
- using bool_constant = std::integral_constant<bool, B>;
- template <typename...>
- struct conjunction : std::true_type {};
- template <typename B1>
- struct conjunction<B1> : B1 {};
- template <typename B1, typename... Bn>
- struct conjunction<B1, Bn...>
- : std::conditional_t<static_cast<bool>(B1::value), conjunction<Bn...>, B1> {
- };
- template <typename...>
- struct disjunction : std::false_type {};
- template <typename B1>
- struct disjunction<B1> : B1 {};
- template <typename B1, typename... Bn>
- struct disjunction<B1, Bn...>
- : std::conditional_t<static_cast<bool>(B1::value), B1, disjunction<Bn...>> {
- };
- template <typename B>
- struct negation : bool_constant<!static_cast<bool>(B::value)> {};
- template <typename Functor, typename... Args>
- using invoke_result_t = std::result_of_t<Functor && (Args && ...)>;
- template <typename Iter>
- using iter_value_t = typename std::iterator_traits<
- std::remove_cv_t<std::remove_reference_t<Iter>>>::value_type;
- template <typename Iter>
- using iter_reference_t = decltype(*std::declval<Iter&>());
- template <typename Func, typename... Iters>
- using indirect_result_t = invoke_result_t<Func, iter_reference_t<Iters>...>;
- template <typename Iter,
- typename Proj,
- typename IndirectResultT = indirect_result_t<Proj, Iter>>
- struct projected {
- using value_type = std::remove_cv_t<std::remove_reference_t<IndirectResultT>>;
- IndirectResultT operator*() const;
- };
- }
- #undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX
- #undef CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX
- #endif
|