Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: include/private/SkTLogic.h

Issue 1330503006: Add skstd::unique_ptr and use it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Formatting. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/private/SkFunction.h ('k') | include/private/SkTemplates.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkTLogic.h
diff --git a/include/private/SkTLogic.h b/include/private/SkTLogic.h
index 0a71d704dca192c727d6b14a5c740ee863110b15..e7fc3dd40d8d0618323717ad662a35ea597442cd 100644
--- a/include/private/SkTLogic.h
+++ b/include/private/SkTLogic.h
@@ -13,10 +13,15 @@
#ifndef SkTLogic_DEFINED
#define SkTLogic_DEFINED
+#include "SkTypes.h"
+
+#include <stddef.h>
#include <stdint.h>
namespace skstd {
+using nullptr_t = decltype(nullptr);
+
template <typename T, T v> struct integral_constant {
static const/*expr*/ T value = v;
using value_type = T;
@@ -54,6 +59,11 @@ template <typename T> struct remove_reference<T&> { using type = T; };
template <typename T> struct remove_reference<T&&> { using type = T; };
template <typename T> using remove_reference_t = typename remove_reference<T>::type;
+template <typename T> struct remove_extent { using type = T; };
+template <typename T> struct remove_extent<T[]> { using type = T; };
+template <typename T, size_t N> struct remove_extent<T[N]> { using type = T;};
+template <typename T> using remove_extent_t = typename remove_extent<T>::type;
+
template <typename T, typename U> struct is_same : false_type {};
template <typename T> struct is_same<T, T> : true_type {};
@@ -65,6 +75,10 @@ template <typename T> struct is_const<const T> : true_type {};
template <typename T> struct is_volatile : false_type {};
template <typename T> struct is_volatile<volatile T> : true_type {};
+template <typename T> struct is_pointer_detector : false_type {};
+template <typename T> struct is_pointer_detector<T*> : true_type {};
+template <typename T> struct is_pointer : is_pointer_detector<remove_cv_t<T>> {};
+
template <typename T> struct is_reference : false_type {};
template <typename T> struct is_reference<T&> : true_type {};
template <typename T> struct is_reference<T&&> : true_type {};
@@ -72,12 +86,51 @@ template <typename T> struct is_reference<T&&> : true_type {};
template <typename T> struct is_lvalue_reference : false_type {};
template <typename T> struct is_lvalue_reference<T&> : true_type {};
-template <typename T> struct is_empty_detector {
- struct Derived : public remove_cv_t<T> { char unused; };
- static const bool value = sizeof(Derived) == sizeof(char);
+template <typename T> struct is_rvalue_reference : false_type {};
+template <typename T> struct is_rvalue_reference<T&&> : true_type {};
+
+template <typename T> struct is_class_detector {
+ using yes_type = uint8_t;
+ using no_type = uint16_t;
+ template <typename U> static yes_type clazz(int U::*);
+ template <typename U> static no_type clazz(...);
+ static const/*expr*/ bool value = sizeof(clazz<T>(0)) == sizeof(yes_type) /*&& !is_union<T>::value*/;
+};
+template <typename T> struct is_class : bool_constant<is_class_detector<T>::value> {};
+
+template <typename T, bool = is_class<T>::value> struct is_empty_detector {
+ struct Derived : public T { char unused; };
+ static const/*expr*/ bool value = sizeof(Derived) == sizeof(char);
+};
+template <typename T> struct is_empty_detector<T, false> {
+ static const/*expr*/ bool value = false;
};
template <typename T> struct is_empty : bool_constant<is_empty_detector<T>::value> {};
+template <typename T> struct is_array : false_type {};
+template <typename T> struct is_array<T[]> : true_type {};
+template <typename T, size_t N> struct is_array<T[N]> : true_type {};
+
+// template<typename R, typename... Args> struct is_function<
+// R [calling-convention] (Args...[, ...]) [const] [volatile] [&|&&]> : true_type {};
+// The cv and ref-qualified versions are strange types we're currently avoiding, so not supported.
+// On all platforms, variadic functions only exist in the c calling convention.
+template <typename> struct is_function : false_type { };
+#if !defined(SK_BUILD_FOR_WIN)
+template <typename R, typename... Args> struct is_function<R(Args...)> : true_type {};
+#else
+#if defined(_M_IX86)
+template <typename R, typename... Args> struct is_function<R __cdecl (Args...)> : true_type {};
+template <typename R, typename... Args> struct is_function<R __stdcall (Args...)> : true_type {};
+template <typename R, typename... Args> struct is_function<R __fastcall (Args...)> : true_type {};
+template <typename R, typename... Args> struct is_function<R __vectorcall (Args...)> : true_type {};
+#else
+template <typename R, typename... Args> struct is_function<R __cdecl (Args...)> : true_type {};
+template <typename R, typename... Args> struct is_function<R __vectorcall (Args...)> : true_type {};
+#endif
+#endif
+template <typename R, typename... Args> struct is_function<R(Args..., ...)> : true_type {};
+
template <typename T> struct add_const { using type = const T; };
template <typename T> using add_const_t = typename add_const<T>::type;
@@ -87,11 +140,50 @@ template <typename T> using add_volatile_t = typename add_volatile<T>::type;
template <typename T> struct add_cv { using type = add_volatile_t<add_const_t<T>>; };
template <typename T> using add_cv_t = typename add_cv<T>::type;
-template <typename T> struct add_rvalue_reference {
- using type = conditional_t<is_void<T>::value || is_reference<T>::value, T, T&&>;
-};
+template <typename T> struct add_pointer { using type = remove_reference_t<T>*; };
+template <typename T> using add_pointer_t = typename add_pointer<T>::type;
+
+template <typename T, bool=is_void<T>::value> struct add_lvalue_reference_init { using type = T; };
+template <typename T> struct add_lvalue_reference_init<T, false> { using type = T&; };
+template <typename T> struct add_lvalue_reference : add_lvalue_reference_init<T> { };
+template <typename T> using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;
+
+template <typename T, bool=is_void<T>::value> struct add_rvalue_reference_init { using type = T; };
+template <typename T> struct add_rvalue_reference_init<T, false> { using type = T&&; };
+template <typename T> struct add_rvalue_reference : add_rvalue_reference_init<T> {};
template <typename T> using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;
+/* This is 'just' a forward declaration. */
+template <typename T> add_rvalue_reference_t<T> declval() /*noexcept*/;
+
+template <typename S, typename D, bool=is_void<S>::value||is_function<D>::value||is_array<D>::value>
+struct is_convertible_detector {
+ static const/*expr*/ bool value = is_void<D>::value;
+};
+template <typename S, typename D> struct is_convertible_detector<S, D, false> {
+ using yes_type = uint8_t;
+ using no_type = uint16_t;
+
+ template <typename To> static void param_convertable_to(To);
+
+ template <typename From, typename To>
+ static decltype(param_convertable_to<To>(declval<From>()), yes_type()) convertible(int);
+
+ template <typename, typename> static no_type convertible(...);
+
+ static const/*expr*/ bool value = sizeof(convertible<S, D>(0)) == sizeof(yes_type);
+};
+template<typename S, typename D> struct is_convertible
+ : bool_constant<is_convertible_detector<S, D>::value> { };
+
+template <typename T> struct decay {
+ using U = remove_reference_t<T>;
+ using type = conditional_t<is_array<U>::value,
+ remove_extent_t<U>*,
+ conditional_t<is_function<U>::value, add_pointer_t<U>, remove_cv_t<U>>>;
+};
+template <typename T> using decay_t = typename decay<T>::type;
+
} // namespace skstd
// The sknonstd namespace contains things we would like to be proposed and feel std-ish.
« no previous file with comments | « include/private/SkFunction.h ('k') | include/private/SkTemplates.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698