| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkTemplates_DEFINED | 10 #ifndef SkTemplates_DEFINED |
| 11 #define SkTemplates_DEFINED | 11 #define SkTemplates_DEFINED |
| 12 | 12 |
| 13 #include "../private/SkTLogic.h" |
| 13 #include "SkMath.h" | 14 #include "SkMath.h" |
| 14 #include "SkTypes.h" | 15 #include "SkTypes.h" |
| 15 #include <limits.h> | 16 #include <limits.h> |
| 16 #include <new> | 17 #include <new> |
| 17 | 18 |
| 18 /** \file SkTemplates.h | 19 /** \file SkTemplates.h |
| 19 | 20 |
| 20 This file contains light-weight template classes for type-safe and exception
-safe | 21 This file contains light-weight template classes for type-safe and exception
-safe |
| 21 resource management. | 22 resource management. |
| 22 */ | 23 */ |
| 23 | 24 |
| 24 /** | 25 /** |
| 25 * Marks a local variable as known to be unused (to avoid warnings). | 26 * Marks a local variable as known to be unused (to avoid warnings). |
| 26 * Note that this does *not* prevent the local variable from being optimized aw
ay. | 27 * Note that this does *not* prevent the local variable from being optimized aw
ay. |
| 27 */ | 28 */ |
| 28 template<typename T> inline void sk_ignore_unused_variable(const T&) { } | 29 template<typename T> inline void sk_ignore_unused_variable(const T&) { } |
| 29 | 30 |
| 30 /** | 31 namespace skstd { |
| 31 * SkTIsConst<T>::value is true if the type T is const. | 32 |
| 32 * The type T is constrained not to be an array or reference type. | 33 template <typename T> inline remove_reference_t<T>&& move(T&& t) { |
| 33 */ | 34 return static_cast<remove_reference_t<T>&&>(t); |
| 34 template <typename T> struct SkTIsConst { | 35 } |
| 35 static T* t; | 36 |
| 36 static uint16_t test(const volatile void*); | 37 template <typename T> inline T&& forward(remove_reference_t<T>& t) /*noexcept*/
{ |
| 37 static uint32_t test(volatile void *); | 38 return static_cast<T&&>(t); |
| 38 static const bool value = (sizeof(uint16_t) == sizeof(test(t))); | 39 } |
| 39 }; | 40 template <typename T> inline T&& forward(remove_reference_t<T>&& t) /*noexcept*/
{ |
| 41 static_assert(!is_lvalue_reference<T>::value, |
| 42 "Forwarding an rvalue reference as an lvalue reference is not
allowed."); |
| 43 return static_cast<T&&>(t); |
| 44 } |
| 45 |
| 46 } // namespace skstd |
| 40 | 47 |
| 41 ///@{ | 48 ///@{ |
| 42 /** SkTConstType<T, CONST>::type will be 'const T' if CONST is true, 'T' otherwi
se. */ | 49 /** SkTConstType<T, CONST>::type will be 'const T' if CONST is true, 'T' otherwi
se. */ |
| 43 template <typename T, bool CONST> struct SkTConstType { | 50 template <typename T, bool CONST> struct SkTConstType { |
| 44 typedef T type; | 51 typedef T type; |
| 45 }; | 52 }; |
| 46 template <typename T> struct SkTConstType<T, true> { | 53 template <typename T> struct SkTConstType<T, true> { |
| 47 typedef const T type; | 54 typedef const T type; |
| 48 }; | 55 }; |
| 49 ///@} | 56 ///@} |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 /** | 547 /** |
| 541 * Returns void* because this object does not initialize the | 548 * Returns void* because this object does not initialize the |
| 542 * memory. Use placement new for types that require a cons. | 549 * memory. Use placement new for types that require a cons. |
| 543 */ | 550 */ |
| 544 void* get() { return fStorage.get(); } | 551 void* get() { return fStorage.get(); } |
| 545 private: | 552 private: |
| 546 SkAlignedSStorage<sizeof(T)*N> fStorage; | 553 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 547 }; | 554 }; |
| 548 | 555 |
| 549 #endif | 556 #endif |
| OLD | NEW |