Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: src/utils/SkTLogic.h

Issue 18503009: Fix SkTFits in to work properly with signed/unsigned mixtures. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Address comments by adding comments and assertions. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkTFitsIn.h ('k') | src/utils/win/SkDWriteFontFileStream.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkTLogic.h
===================================================================
--- src/utils/SkTLogic.h (revision 0)
+++ src/utils/SkTLogic.h (working copy)
@@ -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 <typename T, T v> struct SkTIntegralConstant {
+ static const T value = v;
+ typedef T value_type;
+ typedef SkTIntegralConstant<T, v> type;
+};
+
+/** Convenience specialization of SkTIntegralConstant. */
+template <bool b> struct SkTBool : SkTIntegralConstant<bool, b> { };
+
+/** Pre-C++11 version of std::true_type. */
+typedef SkTBool<true> SkTrue;
+
+/** Pre-C++11 version of std::false_type. */
+typedef SkTBool<false> SkFalse;
+
+/** SkTIf_c::type = (condition) ? T : F;
+ * Pre-C++11 version of std::conditional.
+ */
+template <bool condition, typename T, typename F> struct SkTIf_c {
+ typedef F type;
+};
+template <typename T, typename F> struct SkTIf_c<true, T, F> {
+ typedef T type;
+};
+
+/** SkTIf::type = (Condition::value) ? T : F; */
+template <typename Condition, typename T, typename F> struct SkTIf {
+ typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type type;
+};
+
+/** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */
+template <typename a, typename b, typename Both, typename A, typename B, typename Neither>
+struct SkTMux {
+ typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type,
+ typename SkTIf<b, B, Neither>::type>::type type;
+};
+
+#endif
« no previous file with comments | « src/utils/SkTFitsIn.h ('k') | src/utils/win/SkDWriteFontFileStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698