summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortzik <tzik@chromium.org>2016-03-09 23:17:25 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-10 07:19:09 +0000
commit403cb6c9b17343999f09df79b82b56e77bd93839 (patch)
tree4c072eb309fc7e1245e908ce2a8130541e555a42 /base
parent2df71fea360d6abde88d9c0de8fe084cb95f670e (diff)
downloadchromium_src-403cb6c9b17343999f09df79b82b56e77bd93839.zip
chromium_src-403cb6c9b17343999f09df79b82b56e77bd93839.tar.gz
chromium_src-403cb6c9b17343999f09df79b82b56e77bd93839.tar.bz2
Replace template_util.h stuff with C++11 <type_traits>
BUG=554293 Review URL: https://codereview.chromium.org/1774443002 Cr-Commit-Position: refs/heads/master@{#380369}
Diffstat (limited to 'base')
-rw-r--r--base/android/scoped_java_ref.h7
-rw-r--r--base/bind_helpers.h15
-rw-r--r--base/bind_internal.h18
-rw-r--r--base/callback.h1
-rw-r--r--base/callback_internal.h9
-rw-r--r--base/memory/raw_scoped_refptr_mismatch_checker.h18
-rw-r--r--base/memory/scoped_ptr.h5
-rw-r--r--base/memory/weak_ptr.h7
-rw-r--r--base/numerics/safe_numerics_unittest.cc1
-rw-r--r--base/template_util.h110
-rw-r--r--base/template_util_unittest.cc88
11 files changed, 43 insertions, 236 deletions
diff --git a/base/android/scoped_java_ref.h b/base/android/scoped_java_ref.h
index 8dcf2bc..a1b4b13 100644
--- a/base/android/scoped_java_ref.h
+++ b/base/android/scoped_java_ref.h
@@ -8,10 +8,11 @@
#include <jni.h>
#include <stddef.h>
+#include <type_traits>
+
#include "base/base_export.h"
#include "base/logging.h"
#include "base/macros.h"
-#include "base/template_util.h"
namespace base {
namespace android {
@@ -193,7 +194,7 @@ class ScopedJavaLocalRef : public JavaRef<T> {
template<typename U>
void Reset(JNIEnv* env, U obj) {
- static_assert(base::is_convertible<U, T>::value,
+ static_assert(std::is_convertible<U, T>::value,
"U must be convertible to T");
env_ = this->SetNewLocalRef(env, obj);
}
@@ -264,7 +265,7 @@ class ScopedJavaGlobalRef : public JavaRef<T> {
template<typename U>
void Reset(JNIEnv* env, U obj) {
- static_assert(base::is_convertible<U, T>::value,
+ static_assert(std::is_convertible<U, T>::value,
"U must be convertible to T");
this->SetNewGlobalRef(env, obj);
}
diff --git a/base/bind_helpers.h b/base/bind_helpers.h
index a551465..117fc68 100644
--- a/base/bind_helpers.h
+++ b/base/bind_helpers.h
@@ -150,7 +150,6 @@
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
-#include "base/template_util.h"
#include "build/build_config.h"
namespace base {
@@ -262,21 +261,21 @@ class SupportsAddRefAndRelease {
// Helpers to assert that arguments of a recounted type are bound with a
// scoped_refptr.
template <bool IsClasstype, typename T>
-struct UnsafeBindtoRefCountedArgHelper : false_type {
+struct UnsafeBindtoRefCountedArgHelper : std::false_type {
};
template <typename T>
struct UnsafeBindtoRefCountedArgHelper<true, T>
- : integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
+ : std::integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
};
template <typename T>
-struct UnsafeBindtoRefCountedArg : false_type {
+struct UnsafeBindtoRefCountedArg : std::false_type {
};
template <typename T>
struct UnsafeBindtoRefCountedArg<T*>
- : UnsafeBindtoRefCountedArgHelper<is_class<T>::value, T> {
+ : UnsafeBindtoRefCountedArgHelper<std::is_class<T>::value, T> {
};
template <typename T>
@@ -433,14 +432,14 @@ T Unwrap(PassedWrapper<T>& o) {
// The first argument should be the type of the object that will be received by
// the method.
template <bool IsMethod, typename... Args>
-struct IsWeakMethod : public false_type {};
+struct IsWeakMethod : public std::false_type {};
template <typename T, typename... Args>
-struct IsWeakMethod<true, WeakPtr<T>, Args...> : public true_type {};
+struct IsWeakMethod<true, WeakPtr<T>, Args...> : public std::true_type {};
template <typename T, typename... Args>
struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...>
- : public true_type {};
+ : public std::true_type {};
// Packs a list of types to hold them in a single type.
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 38a5756..199467c 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -68,7 +68,7 @@ namespace internal {
// Implementation note: This non-specialized case handles zero-arity case only.
// Non-zero-arity cases should be handled by the specialization below.
template <typename List>
-struct HasNonConstReferenceItem : false_type {};
+struct HasNonConstReferenceItem : std::false_type {};
// Implementation note: Select true_type if the first parameter is a non-const
// reference. Otherwise, skip the first parameter and check rest of parameters
@@ -76,7 +76,7 @@ struct HasNonConstReferenceItem : false_type {};
template <typename T, typename... Args>
struct HasNonConstReferenceItem<TypeList<T, Args...>>
: std::conditional<is_non_const_reference<T>::value,
- true_type,
+ std::true_type,
HasNonConstReferenceItem<TypeList<Args...>>>::type {};
// HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw
@@ -84,7 +84,7 @@ struct HasNonConstReferenceItem<TypeList<T, Args...>>
// Implementation note: This non-specialized case handles zero-arity case only.
// Non-zero-arity cases should be handled by the specialization below.
template <typename... Args>
-struct HasRefCountedTypeAsRawPtr : false_type {};
+struct HasRefCountedTypeAsRawPtr : std::false_type {};
// Implementation note: Select true_type if the first parameter is a raw pointer
// to a RefCounted type. Otherwise, skip the first parameter and check rest of
@@ -92,7 +92,7 @@ struct HasRefCountedTypeAsRawPtr : false_type {};
template <typename T, typename... Args>
struct HasRefCountedTypeAsRawPtr<T, Args...>
: std::conditional<NeedsScopedRefptrButGetsRawPtr<T>::value,
- true_type,
+ std::true_type,
HasRefCountedTypeAsRawPtr<Args...>>::type {};
// BindsArrayToFirstArg selects true_type when |is_method| is true and the first
@@ -101,11 +101,11 @@ struct HasRefCountedTypeAsRawPtr<T, Args...>
// zero-arity case only. Other cases should be handled by the specialization
// below.
template <bool is_method, typename... Args>
-struct BindsArrayToFirstArg : false_type {};
+struct BindsArrayToFirstArg : std::false_type {};
template <typename T, typename... Args>
struct BindsArrayToFirstArg<true, T, Args...>
- : is_array<typename std::remove_reference<T>::type> {};
+ : std::is_array<typename std::remove_reference<T>::type> {};
// HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except
// when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument.
@@ -170,7 +170,7 @@ class RunnableAdapter<R(T::*)(Args...)> {
// MSVC 2013 doesn't support Type Alias of function types.
// Revisit this after we update it to newer version.
typedef R RunType(T*, Args...);
- using IsMethod = true_type;
+ using IsMethod = std::true_type;
explicit RunnableAdapter(R(T::*method)(Args...))
: method_(method) {
@@ -190,7 +190,7 @@ template <typename R, typename T, typename... Args>
class RunnableAdapter<R(T::*)(Args...) const> {
public:
using RunType = R(const T*, Args...);
- using IsMethod = true_type;
+ using IsMethod = std::true_type;
explicit RunnableAdapter(R(T::*method)(Args...) const)
: method_(method) {
@@ -322,7 +322,7 @@ struct InvokeHelper<true, ReturnType, Runnable> {
// WeakCalls are only supported for functions with a void return type.
// Otherwise, the function result would be undefined if the the WeakPtr<>
// is invalidated.
- static_assert(is_void<ReturnType>::value,
+ static_assert(std::is_void<ReturnType>::value,
"weak_ptrs can only bind to methods without return values");
};
diff --git a/base/callback.h b/base/callback.h
index 5f73b7f..c04e90d 100644
--- a/base/callback.h
+++ b/base/callback.h
@@ -7,7 +7,6 @@
#include "base/callback_forward.h"
#include "base/callback_internal.h"
-#include "base/template_util.h"
// NOTE: Header files that do not require the full definition of Callback or
// Closure should #include "base/callback_forward.h" instead of this file.
diff --git a/base/callback_internal.h b/base/callback_internal.h
index 7319614..1670557 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -19,7 +19,6 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/template_util.h"
namespace base {
namespace internal {
@@ -127,7 +126,13 @@ extern template class CallbackBase<CopyMode::Copyable>;
// confuses template deduction in VS2013 with certain types such as
// std::unique_ptr.
// TODO(dcheng): Revisit this when Windows switches to VS2015 by default.
+
template <typename T> struct IsMoveOnlyType {
+ // Types YesType and NoType are guaranteed such that sizeof(YesType) <
+ // sizeof(NoType).
+ using YesType = char;
+ struct NoType { YesType dummy[2]; };
+
template <typename U>
static YesType Test(const typename U::MoveOnlyTypeForCPP03*);
@@ -135,7 +140,7 @@ template <typename T> struct IsMoveOnlyType {
static NoType Test(...);
static const bool value = sizeof((Test<T>(0))) == sizeof(YesType) &&
- !is_const<T>::value;
+ !std::is_const<T>::value;
};
// Specialization of IsMoveOnlyType so that std::unique_ptr is still considered
diff --git a/base/memory/raw_scoped_refptr_mismatch_checker.h b/base/memory/raw_scoped_refptr_mismatch_checker.h
index 1e88b48..5dbc183 100644
--- a/base/memory/raw_scoped_refptr_mismatch_checker.h
+++ b/base/memory/raw_scoped_refptr_mismatch_checker.h
@@ -5,10 +5,10 @@
#ifndef BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
#define BASE_MEMORY_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
+#include <tuple>
+#include <type_traits>
+
#include "base/memory/ref_counted.h"
-#include "base/template_util.h"
-#include "base/tuple.h"
-#include "build/build_config.h"
// It is dangerous to post a task with a T* argument where T is a subtype of
// RefCounted(Base|ThreadSafeBase), since by the time the parameter is used, the
@@ -25,20 +25,14 @@ namespace internal {
template <typename T>
struct NeedsScopedRefptrButGetsRawPtr {
-#if defined(OS_WIN)
- enum {
- value = base::false_type::value
- };
-#else
enum {
// Human readable translation: you needed to be a scoped_refptr if you are a
// raw pointer type and are convertible to a RefCounted(Base|ThreadSafeBase)
// type.
- value = (is_pointer<T>::value &&
- (is_convertible<T, subtle::RefCountedBase*>::value ||
- is_convertible<T, subtle::RefCountedThreadSafeBase*>::value))
+ value = (std::is_pointer<T>::value &&
+ (std::is_convertible<T, subtle::RefCountedBase*>::value ||
+ std::is_convertible<T, subtle::RefCountedThreadSafeBase*>::value))
};
-#endif
};
template <typename Params>
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h
index 358e9f1..db0d04b 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -102,7 +102,6 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/move.h"
-#include "base/template_util.h"
#include "build/build_config.h"
namespace base {
@@ -179,8 +178,8 @@ namespace internal {
template <typename T> struct IsNotRefCounted {
enum {
- value = !base::is_convertible<T*, base::subtle::RefCountedBase*>::value &&
- !base::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>::
+ value = !std::is_convertible<T*, base::subtle::RefCountedBase*>::value &&
+ !std::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>::
value
};
};
diff --git a/base/memory/weak_ptr.h b/base/memory/weak_ptr.h
index 4e50c27..9ba5e25 100644
--- a/base/memory/weak_ptr.h
+++ b/base/memory/weak_ptr.h
@@ -70,12 +70,13 @@
#ifndef BASE_MEMORY_WEAK_PTR_H_
#define BASE_MEMORY_WEAK_PTR_H_
+#include <type_traits>
+
#include "base/base_export.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
-#include "base/template_util.h"
namespace base {
@@ -160,8 +161,8 @@ class SupportsWeakPtrBase {
// function that makes calling this easier.
template<typename Derived>
static WeakPtr<Derived> StaticAsWeakPtr(Derived* t) {
- typedef
- is_convertible<Derived, internal::SupportsWeakPtrBase&> convertible;
+ using convertible =
+ std::is_convertible<Derived*, internal::SupportsWeakPtrBase*>;
static_assert(convertible::value,
"AsWeakPtr argument must inherit from SupportsWeakPtr");
return AsWeakPtrImpl<Derived>(t, *t);
diff --git a/base/numerics/safe_numerics_unittest.cc b/base/numerics/safe_numerics_unittest.cc
index cb63ad0..861f515 100644
--- a/base/numerics/safe_numerics_unittest.cc
+++ b/base/numerics/safe_numerics_unittest.cc
@@ -11,7 +11,6 @@
#include "base/compiler_specific.h"
#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
-#include "base/template_util.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/base/template_util.h b/base/template_util.h
index d58807a..0c3cac2 100644
--- a/base/template_util.h
+++ b/base/template_util.h
@@ -5,117 +5,15 @@
#ifndef BASE_TEMPLATE_UTIL_H_
#define BASE_TEMPLATE_UTIL_H_
-#include <stddef.h>
+#include <type_traits>
#include "build/build_config.h"
namespace base {
-// template definitions from tr1
-
-template<class T, T v>
-struct integral_constant {
- static const T value = v;
- typedef T value_type;
- typedef integral_constant<T, v> type;
-};
-
-template <class T, T v> const T integral_constant<T, v>::value;
-
-typedef integral_constant<bool, true> true_type;
-typedef integral_constant<bool, false> false_type;
-
-template <class T> struct is_pointer : false_type {};
-template <class T> struct is_pointer<T*> : true_type {};
-
-// Member function pointer detection. This is built-in to C++ 11's stdlib, and
-// we can remove this when we switch to it.
-template<typename T>
-struct is_member_function_pointer : false_type {};
-
-template <typename R, typename Z, typename... A>
-struct is_member_function_pointer<R(Z::*)(A...)> : true_type {};
-template <typename R, typename Z, typename... A>
-struct is_member_function_pointer<R(Z::*)(A...) const> : true_type {};
-
-
-template <class T, class U> struct is_same : public false_type {};
-template <class T> struct is_same<T,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 {};
-
-template <class T> struct is_const : false_type {};
-template <class T> struct is_const<const T> : true_type {};
-
-template <class T> struct is_void : false_type {};
-template <> struct is_void<void> : true_type {};
-
-namespace internal {
-
-// Types YesType and NoType are guaranteed such that sizeof(YesType) <
-// sizeof(NoType).
-typedef char YesType;
-
-struct NoType {
- YesType dummy[2];
-};
-
-// This class is an implementation detail for is_convertible, and you
-// don't need to know how it works to use is_convertible. For those
-// who care: we declare two different functions, one whose argument is
-// of type To and one with a variadic argument list. We give them
-// return types of different size, so we can use sizeof to trick the
-// compiler into telling us which function it would have chosen if we
-// had called it with an argument of type From. See Alexandrescu's
-// _Modern C++ Design_ for more details on this sort of trick.
-
-struct ConvertHelper {
- template <typename To>
- static YesType Test(To);
-
- template <typename To>
- static NoType Test(...);
-
- template <typename From>
- static From& Create();
-};
-
-// 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
-
-// Inherits from true_type if From is convertible to To, false_type otherwise.
-//
-// Note that if the type is convertible, this will be a true_type REGARDLESS
-// of whether or not the conversion would emit a warning.
-template <typename From, typename To>
-struct is_convertible
- : integral_constant<bool,
- sizeof(internal::ConvertHelper::Test<To>(
- internal::ConvertHelper::Create<From>())) ==
- sizeof(internal::YesType)> {
-};
-
-template <typename T>
-struct is_class
- : integral_constant<bool,
- sizeof(internal::IsClassHelper::Test<T>(0)) ==
- sizeof(internal::YesType)> {
-};
+template <class T> struct is_non_const_reference : std::false_type {};
+template <class T> struct is_non_const_reference<T&> : std::true_type {};
+template <class T> struct is_non_const_reference<const T&> : std::false_type {};
} // namespace base
diff --git a/base/template_util_unittest.cc b/base/template_util_unittest.cc
index b960ab1..25441cd 100644
--- a/base/template_util_unittest.cc
+++ b/base/template_util_unittest.cc
@@ -9,99 +9,11 @@
namespace base {
namespace {
-struct AStruct {};
-class AClass {};
-enum AnEnum {};
-
-class Parent {};
-class Child : public Parent {};
-
-// is_pointer<Type>
-static_assert(!is_pointer<int>::value, "IsPointer");
-static_assert(!is_pointer<int&>::value, "IsPointer");
-static_assert(is_pointer<int*>::value, "IsPointer");
-static_assert(is_pointer<const int*>::value, "IsPointer");
-
-// is_array<Type>
-static_assert(!is_array<int>::value, "IsArray");
-static_assert(!is_array<int*>::value, "IsArray");
-static_assert(!is_array<int (*)[3]>::value, "IsArray");
-static_assert(is_array<int[]>::value, "IsArray");
-static_assert(is_array<const int[]>::value, "IsArray");
-static_assert(is_array<int[3]>::value, "IsArray");
-
// is_non_const_reference<Type>
static_assert(!is_non_const_reference<int>::value, "IsNonConstReference");
static_assert(!is_non_const_reference<const int&>::value,
"IsNonConstReference");
static_assert(is_non_const_reference<int&>::value, "IsNonConstReference");
-// is_convertible<From, To>
-
-// Extra parens needed to make preprocessor macro parsing happy. Otherwise,
-// it sees the equivalent of:
-//
-// (is_convertible < Child), (Parent > ::value)
-//
-// Silly C++.
-static_assert((is_convertible<Child, Parent>::value), "IsConvertible");
-static_assert(!(is_convertible<Parent, Child>::value), "IsConvertible");
-static_assert(!(is_convertible<Parent, AStruct>::value), "IsConvertible");
-static_assert((is_convertible<int, double>::value), "IsConvertible");
-static_assert((is_convertible<int*, void*>::value), "IsConvertible");
-static_assert(!(is_convertible<void*, int*>::value), "IsConvertible");
-
-// Array types are an easy corner case. Make sure to test that
-// it does indeed compile.
-static_assert(!(is_convertible<int[10], double>::value), "IsConvertible");
-static_assert(!(is_convertible<double, int[10]>::value), "IsConvertible");
-static_assert((is_convertible<int[10], int*>::value), "IsConvertible");
-
-// is_same<Type1, Type2>
-static_assert(!(is_same<Child, Parent>::value), "IsSame");
-static_assert(!(is_same<Parent, Child>::value), "IsSame");
-static_assert((is_same<Parent, Parent>::value), "IsSame");
-static_assert((is_same<int*, int*>::value), "IsSame");
-static_assert((is_same<int, int>::value), "IsSame");
-static_assert((is_same<void, void>::value), "IsSame");
-static_assert(!(is_same<int, double>::value), "IsSame");
-
-// is_class<Type>
-static_assert(is_class<AStruct>::value, "IsClass");
-static_assert(is_class<AClass>::value, "IsClass");
-static_assert(!is_class<AnEnum>::value, "IsClass");
-static_assert(!is_class<int>::value, "IsClass");
-static_assert(!is_class<char*>::value, "IsClass");
-static_assert(!is_class<int&>::value, "IsClass");
-static_assert(!is_class<char[3]>::value, "IsClass");
-
-static_assert(!is_member_function_pointer<int>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<int*>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<void*>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<AStruct>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<AStruct*>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<void (*)()>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<int (*)(int)>::value,
- "IsMemberFunctionPointer");
-static_assert(!is_member_function_pointer<int (*)(int, int)>::value,
- "IsMemberFunctionPointer");
-
-static_assert(is_member_function_pointer<void (AStruct::*)()>::value,
- "IsMemberFunctionPointer");
-static_assert(is_member_function_pointer<void (AStruct::*)(int)>::value,
- "IsMemberFunctionPointer");
-static_assert(is_member_function_pointer<int (AStruct::*)(int)>::value,
- "IsMemberFunctionPointer");
-static_assert(is_member_function_pointer<int (AStruct::*)(int) const>::value,
- "IsMemberFunctionPointer");
-static_assert(is_member_function_pointer<int (AStruct::*)(int, int)>::value,
- "IsMemberFunctionPointer");
-
} // namespace
} // namespace base