1 // Copyright (c) 2018 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_HEAP_TRAITS_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_HEAP_TRAITS_H_ 7 8 #include <type_traits> 9 #include "third_party/blink/renderer/platform/heap/heap_allocator.h" 10 #include "third_party/blink/renderer/platform/heap/member.h" 11 #include "third_party/blink/renderer/platform/wtf/type_traits.h" 12 13 namespace blink { 14 15 // Given a type T, returns a type that is either Member<T> or just T depending 16 // on whether T is a garbage-collected type. 17 template <typename T> 18 using AddMemberIfNeeded = 19 std::conditional_t<WTF::IsGarbageCollectedType<T>::value, Member<T>, T>; 20 21 // Given a type T, returns a type that is either HeapVector<T>, 22 // HeapVector<Member<T>> or Vector<T> depending on T. 23 template <typename T> 24 using VectorOf = std::conditional_t<WTF::IsTraceable<T>::value, 25 HeapVector<AddMemberIfNeeded<T>>, 26 Vector<T>>; 27 28 // Given types T and U, returns a type that is one of the following: 29 // - HeapVector<std::pair<V, X>> 30 // (where V is either T or Member<T> and X is either U or Member<U>) 31 // - Vector<std::pair<T, U>> 32 template <typename T, typename U> 33 using VectorOfPairs = std::conditional_t< 34 WTF::IsTraceable<T>::value || WTF::IsTraceable<U>::value, 35 HeapVector<std::pair<AddMemberIfNeeded<T>, AddMemberIfNeeded<U>>>, 36 Vector<std::pair<T, U>>>; 37 38 } // namespace blink 39 40 #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_IMPL_HEAP_TRAITS_H_ 41