michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: * michael@0: * michael@0: * This header provides some of the helpers (std::integral_constant) and michael@0: * type transformations (std::conditional) which will become available with michael@0: * C++11 in the type_traits header. michael@0: * michael@0: * Because we lack constexpr, we cannot mimic michael@0: * std::integral_constant::'constexpr operator T()'. michael@0: * As a result we introduce SkTBool and SkTIf similar to Boost in order to michael@0: * minimize the visual noise of many uses of '::value'. michael@0: */ michael@0: michael@0: #ifndef SkTLogic_DEFINED michael@0: #define SkTLogic_DEFINED michael@0: michael@0: /** Represents a templated integer constant. michael@0: * Pre-C++11 version of std::integral_constant. michael@0: */ michael@0: template struct SkTIntegralConstant { michael@0: static const T value = v; michael@0: typedef T value_type; michael@0: typedef SkTIntegralConstant type; michael@0: }; michael@0: michael@0: /** Convenience specialization of SkTIntegralConstant. */ michael@0: template struct SkTBool : SkTIntegralConstant { }; michael@0: michael@0: /** Pre-C++11 version of std::true_type. */ michael@0: typedef SkTBool SkTrue; michael@0: michael@0: /** Pre-C++11 version of std::false_type. */ michael@0: typedef SkTBool SkFalse; michael@0: michael@0: /** SkTIf_c::type = (condition) ? T : F; michael@0: * Pre-C++11 version of std::conditional. michael@0: */ michael@0: template struct SkTIf_c { michael@0: typedef F type; michael@0: }; michael@0: template struct SkTIf_c { michael@0: typedef T type; michael@0: }; michael@0: michael@0: /** SkTIf::type = (Condition::value) ? T : F; */ michael@0: template struct SkTIf { michael@0: typedef typename SkTIf_c(Condition::value), T, F>::type type; michael@0: }; michael@0: michael@0: /** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */ michael@0: template michael@0: struct SkTMux { michael@0: typedef typename SkTIf::type, michael@0: typename SkTIf::type>::type type; michael@0: }; michael@0: michael@0: #endif