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

Unified Diff: base/template_util.h

Issue 6109007: Unified callback system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/base
Patch Set: Address Will's comments. Created 9 years, 10 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 | « base/callback_old.h ('k') | base/template_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/template_util.h
diff --git a/base/template_util.h b/base/template_util.h
index 27bdb7348890571b1e7628ba1c908dfab330afa9..0408fc67a6e45a76664d0400126f139dbffab061 100644
--- a/base/template_util.h
+++ b/base/template_util.h
@@ -6,6 +6,8 @@
#define BASE_TEMPLATE_UTIL_H_
#pragma once
+#include <cstddef> // For size_t.
+
#include "build/build_config.h"
namespace base {
@@ -27,14 +29,22 @@ typedef integral_constant<bool, false> false_type;
template <class T> struct is_pointer : false_type {};
template <class T> struct is_pointer<T*> : true_type {};
+template<class> struct is_array : public false_type {};
+template<class T, size_t n> struct is_array<T[n]> : public true_type {};
+template<class T> struct is_array<T[]> : public true_type {};
+
+template <class T> struct is_non_const_reference : false_type {};
+template <class T> struct is_non_const_reference<T&> : true_type {};
+template <class T> struct is_non_const_reference<const T&> : false_type {};
+
namespace internal {
-// Types small_ and big_ are guaranteed such that sizeof(small_) <
-// sizeof(big_)
-typedef char small_;
+// Types YesType and NoType are guaranteed such that sizeof(YesType) <
+// sizeof(NoType).
+typedef char YesType;
-struct big_ {
- small_ dummy[2];
+struct NoType {
+ YesType dummy[2];
};
#if !defined(OS_WIN)
@@ -50,13 +60,23 @@ struct big_ {
template <typename From, typename To>
struct ConvertHelper {
- static small_ Test(To);
- static big_ Test(...);
+ static YesType Test(To);
+ static NoType Test(...);
static From Create();
};
#endif // !defined(OS_WIN)
+// Used to determine if a type is a struct/union/class. Inspired by Boost's
+// is_class type_trait implementation.
+struct IsClassHelper {
+ template <typename C>
+ static YesType Test(void(C::*)(void));
+
+ template <typename C>
+ static NoType Test(...);
+};
+
} // namespace internal
#if !defined(OS_WIN)
@@ -67,11 +87,18 @@ struct is_convertible
: integral_constant<bool,
sizeof(internal::ConvertHelper<From, To>::Test(
internal::ConvertHelper<From, To>::Create()))
- == sizeof(internal::small_)> {
+ == sizeof(internal::YesType)> {
};
#endif // !defined(OS_WIN)
+template <typename T>
+struct is_class
+ : integral_constant<bool,
+ sizeof(internal::IsClassHelper::Test<T>(0)) ==
+ sizeof(internal::YesType)> {
+};
+
} // namespace base
#endif // BASE_TEMPLATE_UTIL_H_
« no previous file with comments | « base/callback_old.h ('k') | base/template_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698