gfx/skia/trunk/src/utils/SkTLogic.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/utils/SkTLogic.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + *
    1.10 + *
    1.11 + * This header provides some of the helpers (std::integral_constant) and
    1.12 + * type transformations (std::conditional) which will become available with
    1.13 + * C++11 in the type_traits header.
    1.14 + *
    1.15 + * Because we lack constexpr, we cannot mimic
    1.16 + * std::integral_constant::'constexpr operator T()'.
    1.17 + * As a result we introduce SkTBool and SkTIf similar to Boost in order to
    1.18 + * minimize the visual noise of many uses of '::value'.
    1.19 + */
    1.20 +
    1.21 +#ifndef SkTLogic_DEFINED
    1.22 +#define SkTLogic_DEFINED
    1.23 +
    1.24 +/** Represents a templated integer constant.
    1.25 + *  Pre-C++11 version of std::integral_constant.
    1.26 + */
    1.27 +template <typename T, T v> struct SkTIntegralConstant {
    1.28 +    static const T value = v;
    1.29 +    typedef T value_type;
    1.30 +    typedef SkTIntegralConstant<T, v> type;
    1.31 +};
    1.32 +
    1.33 +/** Convenience specialization of SkTIntegralConstant. */
    1.34 +template <bool b> struct SkTBool : SkTIntegralConstant<bool, b> { };
    1.35 +
    1.36 +/** Pre-C++11 version of std::true_type. */
    1.37 +typedef SkTBool<true> SkTrue;
    1.38 +
    1.39 +/** Pre-C++11 version of std::false_type. */
    1.40 +typedef SkTBool<false> SkFalse;
    1.41 +
    1.42 +/** SkTIf_c::type = (condition) ? T : F;
    1.43 + *  Pre-C++11 version of std::conditional.
    1.44 + */
    1.45 +template <bool condition, typename T, typename F> struct SkTIf_c {
    1.46 +    typedef F type;
    1.47 +};
    1.48 +template <typename T, typename F> struct SkTIf_c<true, T, F> {
    1.49 +    typedef T type;
    1.50 +};
    1.51 +
    1.52 +/** SkTIf::type = (Condition::value) ? T : F; */
    1.53 +template <typename Condition, typename T, typename F> struct SkTIf {
    1.54 +    typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type type;
    1.55 +};
    1.56 +
    1.57 +/** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */
    1.58 +template <typename a, typename b, typename Both, typename A, typename B, typename Neither>
    1.59 +struct SkTMux {
    1.60 +    typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type,
    1.61 +                              typename SkTIf<b, B, Neither>::type>::type type;
    1.62 +};
    1.63 +
    1.64 +#endif

mercurial