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