summaryrefslogtreecommitdiffstats
path: root/base/template_util.h
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 01:27:38 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 01:27:38 +0000
commitb38d3578e53d0a7f441c6858334a2d9f08e5c024 (patch)
tree917a1d893c40fd10408e172b1a66cba692a0fedc /base/template_util.h
parentc41fe6697e38057138cbe33332d9882e0d7d9b4b (diff)
downloadchromium_src-b38d3578e53d0a7f441c6858334a2d9f08e5c024.zip
chromium_src-b38d3578e53d0a7f441c6858334a2d9f08e5c024.tar.gz
chromium_src-b38d3578e53d0a7f441c6858334a2d9f08e5c024.tar.bz2
Unified callback system based on tr1::function/tr1::bind and Google's internal callback code.
This callback system allows for creation of functors for normal functions, methods, and const methods. It is a superset of the functionality of NewRunnableMethod, NewRunnableFunction, NewCallback, and CreateFunctor. We support partial binding of function arguments, and also specification of refcounting semantics by wrapping a target object in a wrapper object. BUG=35223 TEST=none Review URL: http://codereview.chromium.org/6109007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/template_util.h')
-rw-r--r--base/template_util.h43
1 files changed, 35 insertions, 8 deletions
diff --git a/base/template_util.h b/base/template_util.h
index 27bdb73..0408fc6 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_