diff options
author | Abseil Team <absl-team@google.com> | 2018-06-28T17·18-0700 |
---|---|---|
committer | Alex Strelnikov <strel@google.com> | 2018-06-28T19·01-0400 |
commit | ba8d6cf07766263723e86736f20a51c1c9c67b19 (patch) | |
tree | fb520ff02a8b1e34b36c4b6e2654dc530cc40671 /absl/container | |
parent | be1e84b988fceabcea4fc9e93f899539f0c81901 (diff) |
Export of internal Abseil changes.
-- 6769c6ebe79804063d68d70a5623a1475d63aeff by Alex Strelnikov <strel@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 202500218 -- c65cc4af08b8c48ca65f0816c1d2f59c7de7b0a5 by Derek Mauro <dmauro@google.com>: Fix DirectMMap on s390x (GitHub #135). This is *untested* because no s390x system is available. PiperOrigin-RevId: 202484458 -- 0ae7b628d7859cb3af169d007c29efd7917bb3ea by Abseil Team <absl-team@google.com>: Changes the Holder's compile-type type decision making to a std::conditional for improved readability PiperOrigin-RevId: 202340646 GitOrigin-RevId: 6769c6ebe79804063d68d70a5623a1475d63aeff Change-Id: I8f9d049ee279b1b1e3381fdf7e6fe9a4ea228306
Diffstat (limited to 'absl/container')
-rw-r--r-- | absl/container/fixed_array.h | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/absl/container/fixed_array.h b/absl/container/fixed_array.h index 295f01088d21..990b65ddd6e5 100644 --- a/absl/container/fixed_array.h +++ b/absl/container/fixed_array.h @@ -78,6 +78,8 @@ constexpr static auto kFixedArrayUseDefault = static_cast<size_t>(-1); // operators. template <typename T, size_t inlined = kFixedArrayUseDefault> class FixedArray { + static_assert(!std::is_array<T>::value || std::extent<T>::value > 0, + "Arrays with unknown bounds cannot be used with FixedArray."); static constexpr size_t kInlineBytesDefault = 256; // std::iterator_traits isn't guaranteed to be SFINAE-friendly until C++17, @@ -337,11 +339,12 @@ class FixedArray { } private: - // HolderTraits + // Holder // - // Wrapper to hold elements of type T for the case where T is an array type. - // If 'T' is an array type, HolderTraits::type is a struct with a 'T v;'. - // Otherwise, HolderTraits::type is simply 'T'. + // Wrapper for holding elements of type T for both the case where T is a + // C-style array type and the general case where it is not. This is needed for + // construction and destruction of the entire array regardless of how many + // dimensions it has. // // Maintainer's Note: The simpler solution would be to simply wrap T in a // struct whether it's an array or not: 'struct Holder { T v; };', but @@ -356,35 +359,23 @@ class FixedArray { // error: call to int __builtin___sprintf_chk(etc...) // will always overflow destination buffer [-Werror] // - class HolderTraits { - template <typename U> - struct SelectImpl { - using type = U; - static pointer AsValue(type* p) { return p; } - }; - - // Partial specialization for elements of array type. - template <typename U, size_t N> - struct SelectImpl<U[N]> { - struct Holder { U v[N]; }; - using type = Holder; - static pointer AsValue(type* p) { return &p->v; } - }; - using Impl = SelectImpl<value_type>; + template <typename OuterT = value_type, + typename InnerT = absl::remove_extent_t<OuterT>, + size_t InnerN = std::extent<OuterT>::value> + struct ArrayHolder { + InnerT array[InnerN]; + }; - public: - using type = typename Impl::type; + using Holder = absl::conditional_t<std::is_array<value_type>::value, + ArrayHolder<value_type>, value_type>; - static pointer AsValue(type *p) { return Impl::AsValue(p); } + static_assert(sizeof(Holder) == sizeof(value_type), ""); + static_assert(alignof(Holder) == alignof(value_type), ""); - // TODO(billydonahue): fix the type aliasing violation - // this assertion hints at. - static_assert(sizeof(type) == sizeof(value_type), - "Holder must be same size as value_type"); - }; - - using Holder = typename HolderTraits::type; - static pointer AsValue(Holder *p) { return HolderTraits::AsValue(p); } + static pointer AsValue(pointer ptr) { return ptr; } + static pointer AsValue(ArrayHolder<value_type>* ptr) { + return std::addressof(ptr->array); + } // InlineSpace // |