diff -r 000000000000 -r 6474c204b198 gfx/skia/trunk/src/utils/SkTLogic.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gfx/skia/trunk/src/utils/SkTLogic.h Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,61 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * + * This header provides some of the helpers (std::integral_constant) and + * type transformations (std::conditional) which will become available with + * C++11 in the type_traits header. + * + * Because we lack constexpr, we cannot mimic + * std::integral_constant::'constexpr operator T()'. + * As a result we introduce SkTBool and SkTIf similar to Boost in order to + * minimize the visual noise of many uses of '::value'. + */ + +#ifndef SkTLogic_DEFINED +#define SkTLogic_DEFINED + +/** Represents a templated integer constant. + * Pre-C++11 version of std::integral_constant. + */ +template struct SkTIntegralConstant { + static const T value = v; + typedef T value_type; + typedef SkTIntegralConstant type; +}; + +/** Convenience specialization of SkTIntegralConstant. */ +template struct SkTBool : SkTIntegralConstant { }; + +/** Pre-C++11 version of std::true_type. */ +typedef SkTBool SkTrue; + +/** Pre-C++11 version of std::false_type. */ +typedef SkTBool SkFalse; + +/** SkTIf_c::type = (condition) ? T : F; + * Pre-C++11 version of std::conditional. + */ +template struct SkTIf_c { + typedef F type; +}; +template struct SkTIf_c { + typedef T type; +}; + +/** SkTIf::type = (Condition::value) ? T : F; */ +template struct SkTIf { + typedef typename SkTIf_c(Condition::value), T, F>::type type; +}; + +/** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */ +template +struct SkTMux { + typedef typename SkTIf::type, + typename SkTIf::type>::type type; +}; + +#endif