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 template <typename T> inline typename SkTRemoveReference<T>::type&& SkMove(T&& t ) { |
mtklein
2015/08/05 17:48:00
I'd personally be satisfied with
// SkMove == std
| |
31 * SkTIsConst<T>::value is true if the type T is const. | 32 return static_cast<typename SkTRemoveReference<T>::type&&>(t); |
32 * The type T is constrained not to be an array or reference type. | 33 } |
33 */ | 34 |
34 template <typename T> struct SkTIsConst { | 35 template <typename T> inline T&& SkTForward(typename SkTRemoveReference<T>::type & t) /*noexcept*/ { |
35 static T* t; | 36 return static_cast<T&&>(t); |
36 static uint16_t test(const volatile void*); | 37 } |
37 static uint32_t test(volatile void *); | 38 template <typename T> inline T&& SkTForward(typename SkTRemoveReference<T>::type && t) /*noexcept*/ { |
38 static const bool value = (sizeof(uint16_t) == sizeof(test(t))); | 39 static_assert(!SkTIsLValueReference<T>::value, |
39 }; | 40 "Forwarding an rvalue reference as an lvalue reference is not allowed."); |
41 return static_cast<T&&>(t); | |
42 } | |
40 | 43 |
41 ///@{ | 44 ///@{ |
42 /** SkTConstType<T, CONST>::type will be 'const T' if CONST is true, 'T' otherwi se. */ | 45 /** SkTConstType<T, CONST>::type will be 'const T' if CONST is true, 'T' otherwi se. */ |
43 template <typename T, bool CONST> struct SkTConstType { | 46 template <typename T, bool CONST> struct SkTConstType { |
44 typedef T type; | 47 typedef T type; |
45 }; | 48 }; |
46 template <typename T> struct SkTConstType<T, true> { | 49 template <typename T> struct SkTConstType<T, true> { |
47 typedef const T type; | 50 typedef const T type; |
48 }; | 51 }; |
49 ///@} | 52 ///@} |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 /** | 543 /** |
541 * Returns void* because this object does not initialize the | 544 * Returns void* because this object does not initialize the |
542 * memory. Use placement new for types that require a cons. | 545 * memory. Use placement new for types that require a cons. |
543 */ | 546 */ |
544 void* get() { return fStorage.get(); } | 547 void* get() { return fStorage.get(); } |
545 private: | 548 private: |
546 SkAlignedSStorage<sizeof(T)*N> fStorage; | 549 SkAlignedSStorage<sizeof(T)*N> fStorage; |
547 }; | 550 }; |
548 | 551 |
549 #endif | 552 #endif |
OLD | NEW |