| 1 | /* | 
|---|
| 2 | * Copyright 2013 Google Inc. | 
|---|
| 3 | * | 
|---|
| 4 | * Use of this source code is governed by a BSD-style license that can be | 
|---|
| 5 | * found in the LICENSE file. | 
|---|
| 6 | * | 
|---|
| 7 | * | 
|---|
| 8 | * This header provides some std:: features early in the skstd namespace | 
|---|
| 9 | * and several Skia-specific additions in the sknonstd namespace. | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 | #ifndef SkTLogic_DEFINED | 
|---|
| 13 | #define SkTLogic_DEFINED | 
|---|
| 14 |  | 
|---|
| 15 | #include <cstddef> | 
|---|
| 16 | #include <type_traits> | 
|---|
| 17 | #include <utility> | 
|---|
| 18 |  | 
|---|
| 19 | namespace skstd { | 
|---|
| 20 |  | 
|---|
| 21 | // C++17, <variant> | 
|---|
| 22 | struct monostate {}; | 
|---|
| 23 |  | 
|---|
| 24 | // C++17, <type_traits> | 
|---|
| 25 | template<typename...> struct conjunction : std::true_type { }; | 
|---|
| 26 | template<typename T> struct conjunction<T> : T { }; | 
|---|
| 27 | template<typename T, typename... Ts> | 
|---|
| 28 | struct conjunction<T, Ts...> : std::conditional<bool(T::value), conjunction<Ts...>, T>::type { }; | 
|---|
| 29 |  | 
|---|
| 30 | }  // namespace skstd | 
|---|
| 31 |  | 
|---|
| 32 | // The sknonstd namespace contains things we would like to be proposed and feel std-ish. | 
|---|
| 33 | namespace sknonstd { | 
|---|
| 34 |  | 
|---|
| 35 | // The name 'copy' here is fraught with peril. In this case it means 'append', not 'overwrite'. | 
|---|
| 36 | // Alternate proposed names are 'propagate', 'augment', or 'append' (and 'add', but already taken). | 
|---|
| 37 | // std::experimental::propagate_const already exists for other purposes in TSv2. | 
|---|
| 38 | // These also follow the <dest, source> pattern used by boost. | 
|---|
| 39 | template <typename D, typename S> struct copy_const { | 
|---|
| 40 | using type = std::conditional_t<std::is_const<S>::value, std::add_const_t<D>, D>; | 
|---|
| 41 | }; | 
|---|
| 42 | template <typename D, typename S> using copy_const_t = typename copy_const<D, S>::type; | 
|---|
| 43 |  | 
|---|
| 44 | template <typename D, typename S> struct copy_volatile { | 
|---|
| 45 | using type = std::conditional_t<std::is_volatile<S>::value, std::add_volatile_t<D>, D>; | 
|---|
| 46 | }; | 
|---|
| 47 | template <typename D, typename S> using copy_volatile_t = typename copy_volatile<D, S>::type; | 
|---|
| 48 |  | 
|---|
| 49 | template <typename D, typename S> struct copy_cv { | 
|---|
| 50 | using type = copy_volatile_t<copy_const_t<D, S>, S>; | 
|---|
| 51 | }; | 
|---|
| 52 | template <typename D, typename S> using copy_cv_t = typename copy_cv<D, S>::type; | 
|---|
| 53 |  | 
|---|
| 54 | // The name 'same' here means 'overwrite'. | 
|---|
| 55 | // Alternate proposed names are 'replace', 'transfer', or 'qualify_from'. | 
|---|
| 56 | // same_xxx<D, S> can be written as copy_xxx<remove_xxx_t<D>, S> | 
|---|
| 57 | template <typename D, typename S> using same_const = copy_const<std::remove_const_t<D>, S>; | 
|---|
| 58 | template <typename D, typename S> using same_const_t = typename same_const<D, S>::type; | 
|---|
| 59 | template <typename D, typename S> using same_volatile =copy_volatile<std::remove_volatile_t<D>,S>; | 
|---|
| 60 | template <typename D, typename S> using same_volatile_t = typename same_volatile<D, S>::type; | 
|---|
| 61 | template <typename D, typename S> using same_cv = copy_cv<std::remove_cv_t<D>, S>; | 
|---|
| 62 | template <typename D, typename S> using same_cv_t = typename same_cv<D, S>::type; | 
|---|
| 63 |  | 
|---|
| 64 | }  // namespace sknonstd | 
|---|
| 65 |  | 
|---|
| 66 | #endif | 
|---|
| 67 |  | 
|---|