diff options
author | Abseil Team <absl-team@google.com> | 2018-01-05T15·54-0800 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2018-01-08T15·38-0500 |
commit | 4132ce25956a91e1224e0f205b7f8c326304a995 (patch) | |
tree | 724485e8778f91d865db86af663af9e7be3293db /absl/strings/internal/stl_type_traits.h | |
parent | 0271cd35577599fa99b59202da17d3136956e4c0 (diff) |
Changes imported from Abseil "staging" branch:
- 0a519d9a4507158267cc515e0c7c83959d94fc78 Fix missing header include when compiling with _GLIBCXX_D... by Alex Strelnikov <strel@google.com> - d089af70781d92af9a5de2d84c417ddf2c87689a Internal change by Gennadiy Rozental <rogeeff@google.com> - 0d3afc89d3907923ede964d58c6bcca579e8ad65 Test absl::any for exception safety. This test is tempor... by Jon Cohen <cohenjon@google.com> - 29af424b8a3174a7b3e657e478aa30a8a425aee2 Tweak the ABSL type trait library and expand its tests. by Abseil Team <absl-team@google.com> - 99ab42b2ebbe466cc3730fb6b16b5fad848f95af Rollback GLIBCXX_DEBUG fix due to internal breakage. by Alex Strelnikov <strel@google.com> - 1a5bcb93ee16d4dd2170254e54c4b62b38fbf17b Internal change. by Abseil Team <absl-team@google.com> - 46de7d09c7d4aef5b7b5389ce9b4f96b654aac02 absl::string_view::rfind: doc fix. by Abseil Team <absl-team@google.com> - edda4c7ddd2d76fbb5b3fd5226b95082083c57d9 Fix string_view_test with c++17/clang/libc++ to address by Xiaoyi Zhang <zhangxy@google.com> GitOrigin-RevId: 0a519d9a4507158267cc515e0c7c83959d94fc78 Change-Id: Ie27de1be3e79bba011f05e924d34e8fcc62d8de5
Diffstat (limited to 'absl/strings/internal/stl_type_traits.h')
-rw-r--r-- | absl/strings/internal/stl_type_traits.h | 121 |
1 files changed, 77 insertions, 44 deletions
diff --git a/absl/strings/internal/stl_type_traits.h b/absl/strings/internal/stl_type_traits.h index 8c3d877e6356..04c4a5323b86 100644 --- a/absl/strings/internal/stl_type_traits.h +++ b/absl/strings/internal/stl_type_traits.h @@ -79,31 +79,48 @@ struct IsSTLContainer template <typename C, template <typename...> class T, typename = void> struct IsBaseOfSpecializationImpl : std::false_type {}; -// IsBaseOfSpecializationImpl must have three partial specializations, -// because we must only compare templates that take the same number of -// arguments. Otherwise, for example, std::vector can be compared with std::map, -// and fail to compile because of too few or too many template arguments. -// -// We must also SFINAE on the existence of an allocator_type. Otherwise, we may -// try to compare, for example, a std::pair<std::string, std::string> with a -// std::vector<std::string, std:std::string>. This would fail to compile, because -// of expected properties of the type passed in as the allocator. -template <template <typename, typename> class U, - template <typename, typename> class T, typename... Args> +// IsBaseOfSpecializationImpl needs multiple partial specializations to SFINAE +// on the existence of container dependent types and plug them into the STL +// template. +template <typename C, template <typename, typename> class T> +struct IsBaseOfSpecializationImpl< + C, T, absl::void_t<typename C::value_type, typename C::allocator_type>> + : std::is_base_of<C, + T<typename C::value_type, typename C::allocator_type>> {}; +template <typename C, template <typename, typename, typename> class T> struct IsBaseOfSpecializationImpl< - U<Args...>, T, absl::void_t<typename U<Args...>::allocator_type>> - : std::is_base_of<U<Args...>, T<Args...>> {}; -template <template <typename, typename, typename> class U, - template <typename, typename, typename> class T, typename... Args> + C, T, + absl::void_t<typename C::key_type, typename C::key_compare, + typename C::allocator_type>> + : std::is_base_of<C, T<typename C::key_type, typename C::key_compare, + typename C::allocator_type>> {}; +template <typename C, template <typename, typename, typename, typename> class T> +struct IsBaseOfSpecializationImpl< + C, T, + absl::void_t<typename C::key_type, typename C::mapped_type, + typename C::key_compare, typename C::allocator_type>> + : std::is_base_of<C, + T<typename C::key_type, typename C::mapped_type, + typename C::key_compare, typename C::allocator_type>> { +}; +template <typename C, template <typename, typename, typename, typename> class T> struct IsBaseOfSpecializationImpl< - U<Args...>, T, absl::void_t<typename U<Args...>::allocator_type>> - : std::is_base_of<U<Args...>, T<Args...>> {}; -template <template <typename, typename, typename, typename> class U, - template <typename, typename, typename, typename> class T, - typename... Args> + C, T, + absl::void_t<typename C::key_type, typename C::hasher, + typename C::key_equal, typename C::allocator_type>> + : std::is_base_of<C, T<typename C::key_type, typename C::hasher, + typename C::key_equal, typename C::allocator_type>> { +}; +template <typename C, + template <typename, typename, typename, typename, typename> class T> struct IsBaseOfSpecializationImpl< - U<Args...>, T, absl::void_t<typename U<Args...>::allocator_type>> - : std::is_base_of<U<Args...>, T<Args...>> {}; + C, T, + absl::void_t<typename C::key_type, typename C::mapped_type, + typename C::hasher, typename C::key_equal, + typename C::allocator_type>> + : std::is_base_of<C, T<typename C::key_type, typename C::mapped_type, + typename C::hasher, typename C::key_equal, + typename C::allocator_type>> {}; template <typename C, template <typename...> class T> using IsBaseOfSpecialization = IsBaseOfSpecializationImpl<absl::decay_t<C>, T>; @@ -140,31 +157,47 @@ struct IsBaseOfSTLContainer template <typename C, template <typename...> class T, typename = void> struct IsConvertibleToSpecializationImpl : std::false_type {}; -// IsConvertibleToSpecializationImpl must have three partial specializations, -// because we must only compare templates that take the same number of -// arguments. Otherwise, for example, std::vector can be compared with std::map, -// and fail to compile because of too few or too many template arguments. -// -// We must also SFINAE on the existence of an allocator_type. Otherwise, we may -// try to compare, for example, a std::pair<std::string, std::string> with a -// std::vector<std::string, std:std::string>. This would fail to compile, because -// of expected properties of the type passed in as the allocator. -template <template <typename, typename> class U, - template <typename, typename> class T, typename... Args> +// IsConvertibleToSpecializationImpl needs multiple partial specializations to +// SFINAE on the existence of container dependent types and plug them into the +// STL template. +template <typename C, template <typename, typename> class T> +struct IsConvertibleToSpecializationImpl< + C, T, absl::void_t<typename C::value_type, typename C::allocator_type>> + : std::is_convertible< + C, T<typename C::value_type, typename C::allocator_type>> {}; +template <typename C, template <typename, typename, typename> class T> +struct IsConvertibleToSpecializationImpl< + C, T, + absl::void_t<typename C::key_type, typename C::key_compare, + typename C::allocator_type>> + : std::is_convertible<C, T<typename C::key_type, typename C::key_compare, + typename C::allocator_type>> {}; +template <typename C, template <typename, typename, typename, typename> class T> struct IsConvertibleToSpecializationImpl< - U<Args...>, T, absl::void_t<typename U<Args...>::allocator_type>> - : std::is_convertible<U<Args...>, T<Args...>> {}; -template <template <typename, typename, typename> class U, - template <typename, typename, typename> class T, typename... Args> + C, T, + absl::void_t<typename C::key_type, typename C::mapped_type, + typename C::key_compare, typename C::allocator_type>> + : std::is_convertible< + C, T<typename C::key_type, typename C::mapped_type, + typename C::key_compare, typename C::allocator_type>> {}; +template <typename C, template <typename, typename, typename, typename> class T> struct IsConvertibleToSpecializationImpl< - U<Args...>, T, absl::void_t<typename U<Args...>::allocator_type>> - : std::is_convertible<U<Args...>, T<Args...>> {}; -template <template <typename, typename, typename, typename> class U, - template <typename, typename, typename, typename> class T, - typename... Args> + C, T, + absl::void_t<typename C::key_type, typename C::hasher, + typename C::key_equal, typename C::allocator_type>> + : std::is_convertible< + C, T<typename C::key_type, typename C::hasher, typename C::key_equal, + typename C::allocator_type>> {}; +template <typename C, + template <typename, typename, typename, typename, typename> class T> struct IsConvertibleToSpecializationImpl< - U<Args...>, T, absl::void_t<typename U<Args...>::allocator_type>> - : std::is_convertible<U<Args...>, T<Args...>> {}; + C, T, + absl::void_t<typename C::key_type, typename C::mapped_type, + typename C::hasher, typename C::key_equal, + typename C::allocator_type>> + : std::is_convertible<C, T<typename C::key_type, typename C::mapped_type, + typename C::hasher, typename C::key_equal, + typename C::allocator_type>> {}; template <typename C, template <typename...> class T> using IsConvertibleToSpecialization = IsConvertibleToSpecializationImpl<absl::decay_t<C>, T>; |