| 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 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 template <typename T> inline T&& forward(remove_reference_t<T>&& t) /*noexcept*/
{ | 40 template <typename T> inline T&& forward(remove_reference_t<T>&& t) /*noexcept*/
{ |
| 41 static_assert(!is_lvalue_reference<T>::value, | 41 static_assert(!is_lvalue_reference<T>::value, |
| 42 "Forwarding an rvalue reference as an lvalue reference is not
allowed."); | 42 "Forwarding an rvalue reference as an lvalue reference is not
allowed."); |
| 43 return static_cast<T&&>(t); | 43 return static_cast<T&&>(t); |
| 44 } | 44 } |
| 45 | 45 |
| 46 template <typename T> add_rvalue_reference_t<T> declval(); | 46 template <typename T> add_rvalue_reference_t<T> declval(); |
| 47 | 47 |
| 48 } // namespace skstd | 48 } // namespace skstd |
| 49 | 49 |
| 50 ///@{ | |
| 51 /** SkTConstType<T, CONST>::type will be 'const T' if CONST is true, 'T' otherwi
se. */ | |
| 52 template <typename T, bool CONST> struct SkTConstType { | |
| 53 typedef T type; | |
| 54 }; | |
| 55 template <typename T> struct SkTConstType<T, true> { | |
| 56 typedef const T type; | |
| 57 }; | |
| 58 ///@} | |
| 59 | |
| 60 /** | 50 /** |
| 61 * Returns a pointer to a D which comes immediately after S[count]. | 51 * Returns a pointer to a D which comes immediately after S[count]. |
| 62 */ | 52 */ |
| 63 template <typename D, typename S> static D* SkTAfter(S* ptr, size_t count = 1) { | 53 template <typename D, typename S> static D* SkTAfter(S* ptr, size_t count = 1) { |
| 64 return reinterpret_cast<D*>(ptr + count); | 54 return reinterpret_cast<D*>(ptr + count); |
| 65 } | 55 } |
| 66 | 56 |
| 67 /** | 57 /** |
| 68 * Returns a pointer to a D which comes byteOffset bytes after S. | 58 * Returns a pointer to a D which comes byteOffset bytes after S. |
| 69 */ | 59 */ |
| 70 template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs
et) { | 60 template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs
et) { |
| 71 // The intermediate char* has the same const-ness as D as this produces bett
er error messages. | 61 // The intermediate char* has the same cv-ness as D as this produces better
error messages. |
| 72 // This relies on the fact that reinterpret_cast can add constness, but cann
ot remove it. | 62 // This relies on the fact that reinterpret_cast can add constness, but cann
ot remove it. |
| 73 return reinterpret_cast<D*>( | 63 return reinterpret_cast<D*>(reinterpret_cast<sknonstd::same_cv_t<char, D>*>(
ptr) + byteOffset); |
| 74 reinterpret_cast<typename SkTConstType<char, SkTIsConst<D>::value>::type
*>(ptr) + byteOffset | |
| 75 ); | |
| 76 } | 64 } |
| 77 | 65 |
| 78 /** \class SkAutoTCallVProc | 66 /** \class SkAutoTCallVProc |
| 79 | 67 |
| 80 Call a function when this goes out of scope. The template uses two | 68 Call a function when this goes out of scope. The template uses two |
| 81 parameters, the object, and a function that is to be called in the destructo
r. | 69 parameters, the object, and a function that is to be called in the destructo
r. |
| 82 If detach() is called, the object reference is set to null. If the object | 70 If detach() is called, the object reference is set to null. If the object |
| 83 reference is null when the destructor is called, we do not call the | 71 reference is null when the destructor is called, we do not call the |
| 84 function. | 72 function. |
| 85 */ | 73 */ |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 * Returns void* because this object does not initialize the | 538 * Returns void* because this object does not initialize the |
| 551 * memory. Use placement new for types that require a cons. | 539 * memory. Use placement new for types that require a cons. |
| 552 */ | 540 */ |
| 553 void* get() { return fStorage.get(); } | 541 void* get() { return fStorage.get(); } |
| 554 const void* get() const { return fStorage.get(); } | 542 const void* get() const { return fStorage.get(); } |
| 555 private: | 543 private: |
| 556 SkAlignedSStorage<sizeof(T)*N> fStorage; | 544 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 557 }; | 545 }; |
| 558 | 546 |
| 559 #endif | 547 #endif |
| OLD | NEW |