diff options
author | tzik <tzik@chromium.org> | 2015-12-19 01:18:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-19 09:20:02 +0000 |
commit | 3bc7779ba002f50675a18e2eae277d4617788e21 (patch) | |
tree | b7d1186e90b289ea7c101cbc316e7214e4f5a007 | |
parent | 7131453f358de5c014fbb709ef5c15985621849e (diff) | |
download | chromium_src-3bc7779ba002f50675a18e2eae277d4617788e21.zip chromium_src-3bc7779ba002f50675a18e2eae277d4617788e21.tar.gz chromium_src-3bc7779ba002f50675a18e2eae277d4617788e21.tar.bz2 |
Replace typedef with using for Callback/Bind related files
This CL contains:
* Replace typedef with using.
* Remove |void| from no-parameter function declarations.
* Fix an error in a comment.
BUG=
Review URL: https://codereview.chromium.org/1537553002
Cr-Commit-Position: refs/heads/master@{#366278}
-rw-r--r-- | base/bind.h | 15 | ||||
-rw-r--r-- | base/bind_helpers.h | 36 | ||||
-rw-r--r-- | base/bind_internal.h | 32 | ||||
-rw-r--r-- | base/bind_internal_win.h | 8 | ||||
-rw-r--r-- | base/bind_unittest.cc | 92 | ||||
-rw-r--r-- | base/bind_unittest.nc | 24 | ||||
-rw-r--r-- | base/callback.h | 22 | ||||
-rw-r--r-- | base/callback_forward.h | 4 | ||||
-rw-r--r-- | base/callback_internal.h | 22 | ||||
-rw-r--r-- | base/callback_unittest.cc | 33 | ||||
-rw-r--r-- | base/callback_unittest.nc | 10 |
11 files changed, 156 insertions, 142 deletions
diff --git a/base/bind.h b/base/bind.h index 4c2abed..770e457 100644 --- a/base/bind.h +++ b/base/bind.h @@ -55,14 +55,14 @@ base::Callback< typename internal::CallbackParamTraits<Args>::StorageType...> ::UnboundRunType> Bind(Functor functor, const Args&... args) { - // Typedefs for how to store and run the functor. - typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; - typedef typename internal::FunctorTraits<Functor>::RunType RunType; + // Type aliases for how to store and run the functor. + using RunnableType = typename internal::FunctorTraits<Functor>::RunnableType; + using RunType = typename internal::FunctorTraits<Functor>::RunType; // Use RunnableType::RunType instead of RunType above because our - // checks should below for bound references need to know what the actual + // checks below for bound references need to know what the actual // functor is going to interpret the argument as. - typedef typename RunnableType::RunType BoundRunType; + using BoundRunType = typename RunnableType::RunType; using BoundArgs = internal::TakeTypeListItem<sizeof...(Args), @@ -88,10 +88,9 @@ Bind(Functor functor, const Args&... args) { !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, "a parameter is a refcounted type and needs scoped_refptr"); - typedef internal::BindState< + using BindState = internal::BindState< RunnableType, RunType, - typename internal::CallbackParamTraits<Args>::StorageType...> - BindState; + typename internal::CallbackParamTraits<Args>::StorageType...>; return Callback<typename BindState::UnboundRunType>( new BindState(internal::MakeRunnable(functor), args...)); diff --git a/base/bind_helpers.h b/base/bind_helpers.h index 68867c3..7995124 100644 --- a/base/bind_helpers.h +++ b/base/bind_helpers.h @@ -188,7 +188,7 @@ namespace internal { // want to probe for. Then we create a class Base that inherits from both T // (the class we wish to probe) and BaseMixin. Note that the function // signature in BaseMixin does not need to match the signature of the function -// we are probing for; thus it's easiest to just use void(void). +// we are probing for; thus it's easiest to just use void(). // // Now, if TargetFunc exists somewhere in T, then &Base::TargetFunc has an // ambiguous resolution between BaseMixin and T. This lets us write the @@ -225,8 +225,8 @@ namespace internal { // See http://crbug.com/82038. template <typename T> class SupportsAddRefAndRelease { - typedef char Yes[1]; - typedef char No[2]; + using Yes = char[1]; + using No = char[2]; struct BaseMixin { void AddRef(); @@ -245,7 +245,7 @@ class SupportsAddRefAndRelease { #pragma warning(pop) #endif - template <void(BaseMixin::*)(void)> struct Helper {}; + template <void(BaseMixin::*)()> struct Helper {}; template <typename C> static No& Check(Helper<&C::AddRef>*); @@ -279,8 +279,8 @@ struct UnsafeBindtoRefCountedArg<T*> template <typename T> class HasIsMethodTag { - typedef char Yes[1]; - typedef char No[2]; + using Yes = char[1]; + using No = char[2]; template <typename U> static Yes& Check(typename U::IsMethod*); @@ -390,13 +390,13 @@ class PassedWrapper { // Unwrap the stored parameters for the wrappers above. template <typename T> struct UnwrapTraits { - typedef const T& ForwardType; + using ForwardType = const T&; static ForwardType Unwrap(const T& o) { return o; } }; template <typename T> struct UnwrapTraits<UnretainedWrapper<T> > { - typedef T* ForwardType; + using ForwardType = T*; static ForwardType Unwrap(UnretainedWrapper<T> unretained) { return unretained.get(); } @@ -404,7 +404,7 @@ struct UnwrapTraits<UnretainedWrapper<T> > { template <typename T> struct UnwrapTraits<ConstRefWrapper<T> > { - typedef const T& ForwardType; + using ForwardType = const T&; static ForwardType Unwrap(ConstRefWrapper<T> const_ref) { return const_ref.get(); } @@ -412,19 +412,19 @@ struct UnwrapTraits<ConstRefWrapper<T> > { template <typename T> struct UnwrapTraits<scoped_refptr<T> > { - typedef T* ForwardType; + using ForwardType = T*; static ForwardType Unwrap(const scoped_refptr<T>& o) { return o.get(); } }; template <typename T> struct UnwrapTraits<WeakPtr<T> > { - typedef const WeakPtr<T>& ForwardType; + using ForwardType = const WeakPtr<T>&; static ForwardType Unwrap(const WeakPtr<T>& o) { return o; } }; template <typename T> struct UnwrapTraits<OwnedWrapper<T> > { - typedef T* ForwardType; + using ForwardType = T*; static ForwardType Unwrap(const OwnedWrapper<T>& o) { return o.get(); } @@ -432,7 +432,7 @@ struct UnwrapTraits<OwnedWrapper<T> > { template <typename T> struct UnwrapTraits<PassedWrapper<T> > { - typedef T ForwardType; + using ForwardType = T; static T Unwrap(PassedWrapper<T>& o) { return o.Pass(); } @@ -515,12 +515,12 @@ struct DropTypeListItemImpl<n, TypeList<T, List...>> template <typename T, typename... List> struct DropTypeListItemImpl<0, TypeList<T, List...>> { - typedef TypeList<T, List...> Type; + using Type = TypeList<T, List...>; }; template <> struct DropTypeListItemImpl<0, TypeList<>> { - typedef TypeList<> Type; + using Type = TypeList<>; }; // A type-level function that drops |n| list item from given TypeList. @@ -558,7 +558,7 @@ struct ConcatTypeListsImpl; template <typename... Types1, typename... Types2> struct ConcatTypeListsImpl<TypeList<Types1...>, TypeList<Types2...>> { - typedef TypeList<Types1..., Types2...> Type; + using Type = TypeList<Types1..., Types2...>; }; // A type-level function that concats two TypeLists. @@ -571,7 +571,9 @@ struct MakeFunctionTypeImpl; template <typename R, typename... Args> struct MakeFunctionTypeImpl<R, TypeList<Args...>> { - typedef R(Type)(Args...); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef R Type(Args...); }; // A type-level function that constructs a function type that has |R| as its diff --git a/base/bind_internal.h b/base/bind_internal.h index fbf43a0..947df15 100644 --- a/base/bind_internal.h +++ b/base/bind_internal.h @@ -143,7 +143,9 @@ class RunnableAdapter; template <typename R, typename... Args> class RunnableAdapter<R(*)(Args...)> { public: - typedef R (RunType)(Args...); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef R RunType(Args...); explicit RunnableAdapter(R(*function)(Args...)) : function_(function) { @@ -161,8 +163,10 @@ class RunnableAdapter<R(*)(Args...)> { template <typename R, typename T, typename... Args> class RunnableAdapter<R(T::*)(Args...)> { public: - typedef R (RunType)(T*, Args...); - typedef true_type IsMethod; + // 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; explicit RunnableAdapter(R(T::*method)(Args...)) : method_(method) { @@ -180,8 +184,8 @@ class RunnableAdapter<R(T::*)(Args...)> { template <typename R, typename T, typename... Args> class RunnableAdapter<R(T::*)(Args...) const> { public: - typedef R (RunType)(const T*, Args...); - typedef true_type IsMethod; + using RunType = R(const T*, Args...); + using IsMethod = true_type; explicit RunnableAdapter(R(T::*method)(Args...) const) : method_(method) { @@ -205,7 +209,9 @@ struct ForceVoidReturn; template <typename R, typename... Args> struct ForceVoidReturn<R(Args...)> { - typedef void(RunType)(Args...); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef void RunType(Args...); }; @@ -214,21 +220,21 @@ struct ForceVoidReturn<R(Args...)> { // See description at top of file. template <typename T> struct FunctorTraits { - typedef RunnableAdapter<T> RunnableType; - typedef typename RunnableType::RunType RunType; + using RunnableType = RunnableAdapter<T>; + using RunType = typename RunnableType::RunType; }; template <typename T> struct FunctorTraits<IgnoreResultHelper<T>> { - typedef typename FunctorTraits<T>::RunnableType RunnableType; - typedef typename ForceVoidReturn< - typename RunnableType::RunType>::RunType RunType; + using RunnableType = typename FunctorTraits<T>::RunnableType; + using RunType = + typename ForceVoidReturn<typename RunnableType::RunType>::RunType; }; template <typename T> struct FunctorTraits<Callback<T>> { - typedef Callback<T> RunnableType; - typedef typename Callback<T>::RunType RunType; + using RunnableType = Callback<T> ; + using RunType = typename Callback<T>::RunType; }; diff --git a/base/bind_internal_win.h b/base/bind_internal_win.h index c3f7477..42fbf23 100644 --- a/base/bind_internal_win.h +++ b/base/bind_internal_win.h @@ -23,7 +23,9 @@ class RunnableAdapter; template <typename R, typename... Args> class RunnableAdapter<R(__stdcall *)(Args...)> { public: - typedef R (RunType)(Args...); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef R RunType(Args...); explicit RunnableAdapter(R(__stdcall *function)(Args...)) : function_(function) { @@ -41,7 +43,9 @@ class RunnableAdapter<R(__stdcall *)(Args...)> { template <typename R, typename... Args> class RunnableAdapter<R(__fastcall *)(Args...)> { public: - typedef R (RunType)(Args...); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef R RunType(Args...); explicit RunnableAdapter(R(__fastcall *function)(Args...)) : function_(function) { diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc index 4c80001..32c2c4a 100644 --- a/base/bind_unittest.cc +++ b/base/bind_unittest.cc @@ -27,11 +27,11 @@ class NoRef { public: NoRef() {} - MOCK_METHOD0(VoidMethod0, void(void)); - MOCK_CONST_METHOD0(VoidConstMethod0, void(void)); + MOCK_METHOD0(VoidMethod0, void()); + MOCK_CONST_METHOD0(VoidConstMethod0, void()); - MOCK_METHOD0(IntMethod0, int(void)); - MOCK_CONST_METHOD0(IntConstMethod0, int(void)); + MOCK_METHOD0(IntMethod0, int()); + MOCK_CONST_METHOD0(IntConstMethod0, int()); private: // Particularly important in this test to ensure no copies are made. @@ -42,8 +42,8 @@ class HasRef : public NoRef { public: HasRef() {} - MOCK_CONST_METHOD0(AddRef, void(void)); - MOCK_CONST_METHOD0(Release, bool(void)); + MOCK_CONST_METHOD0(AddRef, void()); + MOCK_CONST_METHOD0(Release, bool()); private: // Particularly important in this test to ensure no copies are made. @@ -60,8 +60,8 @@ static const int kChildValue = 2; class Parent { public: - void AddRef(void) const {} - void Release(void) const {} + void AddRef() const {} + void Release() const {} virtual void VirtualSet() { value = kParentValue; } void NonVirtualSet() { value = kParentValue; } int value; @@ -230,11 +230,11 @@ class BindTest : public ::testing::Test { virtual ~BindTest() { } - static void VoidFunc0(void) { + static void VoidFunc0() { static_func_mock_ptr->VoidMethod0(); } - static int IntFunc0(void) { return static_func_mock_ptr->IntMethod0(); } + static int IntFunc0() { return static_func_mock_ptr->IntMethod0(); } protected: StrictMock<NoRef> no_ref_; @@ -254,7 +254,7 @@ StrictMock<NoRef>* BindTest::static_func_mock_ptr; // Sanity check that we can instantiate a callback for each arity. TEST_F(BindTest, ArityTest) { - Callback<int(void)> c0 = Bind(&Sum, 32, 16, 8, 4, 2, 1); + Callback<int()> c0 = Bind(&Sum, 32, 16, 8, 4, 2, 1); EXPECT_EQ(63, c0.Run()); Callback<int(int)> c1 = Bind(&Sum, 32, 16, 8, 4, 2); @@ -296,7 +296,7 @@ TEST_F(BindTest, CurryingTest) { Callback<int(int)> c1 = Bind(c2, 2); EXPECT_EQ(75, c1.Run(13)); - Callback<int(void)> c0 = Bind(c1, 1); + Callback<int()> c0 = Bind(c1, 1); EXPECT_EQ(63, c0.Run()); } @@ -337,7 +337,7 @@ TEST_F(BindTest, FunctionTypeSupport) { EXPECT_CALL(has_ref_, VoidConstMethod0()).Times(2); Closure normal_cb = Bind(&VoidFunc0); - Callback<NoRef*(void)> normal_non_refcounted_cb = + Callback<NoRef*()> normal_non_refcounted_cb = Bind(&PolymorphicIdentity<NoRef*>, &no_ref_); normal_cb.Run(); EXPECT_EQ(&no_ref_, normal_non_refcounted_cb.Run()); @@ -379,11 +379,11 @@ TEST_F(BindTest, ReturnValues) { .WillOnce(Return(41337)) .WillOnce(Return(51337)); - Callback<int(void)> normal_cb = Bind(&IntFunc0); - Callback<int(void)> method_cb = Bind(&HasRef::IntMethod0, &has_ref_); - Callback<int(void)> const_method_nonconst_obj_cb = + Callback<int()> normal_cb = Bind(&IntFunc0); + Callback<int()> method_cb = Bind(&HasRef::IntMethod0, &has_ref_); + Callback<int()> const_method_nonconst_obj_cb = Bind(&HasRef::IntConstMethod0, &has_ref_); - Callback<int(void)> const_method_const_obj_cb = + Callback<int()> const_method_const_obj_cb = Bind(&HasRef::IntConstMethod0, const_has_ref_ptr_); EXPECT_EQ(1337, normal_cb.Run()); EXPECT_EQ(31337, method_cb.Run()); @@ -447,46 +447,46 @@ TEST_F(BindTest, IgnoreResult) { TEST_F(BindTest, ArgumentBinding) { int n = 2; - Callback<int(void)> bind_primitive_cb = Bind(&Identity, n); + Callback<int()> bind_primitive_cb = Bind(&Identity, n); EXPECT_EQ(n, bind_primitive_cb.Run()); - Callback<int*(void)> bind_primitive_pointer_cb = + Callback<int*()> bind_primitive_pointer_cb = Bind(&PolymorphicIdentity<int*>, &n); EXPECT_EQ(&n, bind_primitive_pointer_cb.Run()); - Callback<int(void)> bind_int_literal_cb = Bind(&Identity, 3); + Callback<int()> bind_int_literal_cb = Bind(&Identity, 3); EXPECT_EQ(3, bind_int_literal_cb.Run()); - Callback<const char*(void)> bind_string_literal_cb = + Callback<const char*()> bind_string_literal_cb = Bind(&CStringIdentity, "hi"); EXPECT_STREQ("hi", bind_string_literal_cb.Run()); - Callback<int(void)> bind_template_function_cb = + Callback<int()> bind_template_function_cb = Bind(&PolymorphicIdentity<int>, 4); EXPECT_EQ(4, bind_template_function_cb.Run()); NoRefParent p; p.value = 5; - Callback<int(void)> bind_object_cb = Bind(&UnwrapNoRefParent, p); + Callback<int()> bind_object_cb = Bind(&UnwrapNoRefParent, p); EXPECT_EQ(5, bind_object_cb.Run()); IncompleteType* incomplete_ptr = reinterpret_cast<IncompleteType*>(123); - Callback<IncompleteType*(void)> bind_incomplete_ptr_cb = + Callback<IncompleteType*()> bind_incomplete_ptr_cb = Bind(&PolymorphicIdentity<IncompleteType*>, incomplete_ptr); EXPECT_EQ(incomplete_ptr, bind_incomplete_ptr_cb.Run()); NoRefChild c; c.value = 6; - Callback<int(void)> bind_promotes_cb = Bind(&UnwrapNoRefParent, c); + Callback<int()> bind_promotes_cb = Bind(&UnwrapNoRefParent, c); EXPECT_EQ(6, bind_promotes_cb.Run()); c.value = 7; - Callback<int(void)> bind_pointer_promotes_cb = + Callback<int()> bind_pointer_promotes_cb = Bind(&UnwrapNoRefParentPtr, &c); EXPECT_EQ(7, bind_pointer_promotes_cb.Run()); c.value = 8; - Callback<int(void)> bind_const_reference_promotes_cb = + Callback<int()> bind_const_reference_promotes_cb = Bind(&UnwrapNoRefParentConstRef, c); EXPECT_EQ(8, bind_const_reference_promotes_cb.Run()); } @@ -533,12 +533,12 @@ TEST_F(BindTest, ReferenceArgumentBinding) { int& ref_n = n; const int& const_ref_n = n; - Callback<int(void)> ref_copies_cb = Bind(&Identity, ref_n); + Callback<int()> ref_copies_cb = Bind(&Identity, ref_n); EXPECT_EQ(n, ref_copies_cb.Run()); n++; EXPECT_EQ(n - 1, ref_copies_cb.Run()); - Callback<int(void)> const_ref_copies_cb = Bind(&Identity, const_ref_n); + Callback<int()> const_ref_copies_cb = Bind(&Identity, const_ref_n); EXPECT_EQ(n, const_ref_copies_cb.Run()); n++; EXPECT_EQ(n - 1, const_ref_copies_cb.Run()); @@ -551,10 +551,10 @@ TEST_F(BindTest, ArrayArgumentBinding) { int array[4] = {1, 1, 1, 1}; const int (*const_array_ptr)[4] = &array; - Callback<int(void)> array_cb = Bind(&ArrayGet, array, 1); + Callback<int()> array_cb = Bind(&ArrayGet, array, 1); EXPECT_EQ(1, array_cb.Run()); - Callback<int(void)> const_array_cb = Bind(&ArrayGet, *const_array_ptr, 1); + Callback<int()> const_array_cb = Bind(&ArrayGet, *const_array_ptr, 1); EXPECT_EQ(1, const_array_cb.Run()); array[1] = 3; @@ -592,15 +592,15 @@ TEST_F(BindTest, Unretained) { EXPECT_CALL(no_ref_, VoidMethod0()); EXPECT_CALL(no_ref_, VoidConstMethod0()).Times(2); - Callback<void(void)> method_cb = + Callback<void()> method_cb = Bind(&NoRef::VoidMethod0, Unretained(&no_ref_)); method_cb.Run(); - Callback<void(void)> const_method_cb = + Callback<void()> const_method_cb = Bind(&NoRef::VoidConstMethod0, Unretained(&no_ref_)); const_method_cb.Run(); - Callback<void(void)> const_method_const_ptr_cb = + Callback<void()> const_method_const_ptr_cb = Bind(&NoRef::VoidConstMethod0, Unretained(const_no_ref_ptr_)); const_method_const_ptr_cb.Run(); } @@ -652,8 +652,8 @@ TEST_F(BindTest, WeakPtr) { TEST_F(BindTest, ConstRef) { int n = 1; - Callback<int(void)> copy_cb = Bind(&Identity, n); - Callback<int(void)> const_ref_cb = Bind(&Identity, ConstRef(n)); + Callback<int()> copy_cb = Bind(&Identity, n); + Callback<int()> const_ref_cb = Bind(&Identity, ConstRef(n)); EXPECT_EQ(n, copy_cb.Run()); EXPECT_EQ(n, const_ref_cb.Run()); n++; @@ -663,7 +663,7 @@ TEST_F(BindTest, ConstRef) { int copies = 0; int assigns = 0; CopyCounter counter(&copies, &assigns); - Callback<int(void)> all_const_ref_cb = + Callback<int()> all_const_ref_cb = Bind(&GetCopies, ConstRef(counter)); EXPECT_EQ(0, all_const_ref_cb.Run()); EXPECT_EQ(0, copies); @@ -680,7 +680,7 @@ TEST_F(BindTest, ScopedRefptr) { const scoped_refptr<StrictMock<HasRef> > refptr(&has_ref_); - Callback<int(void)> scoped_refptr_const_ref_cb = + Callback<int()> scoped_refptr_const_ref_cb = Bind(&FunctionWithScopedRefptrFirstParam, base::ConstRef(refptr), 1); EXPECT_EQ(1, scoped_refptr_const_ref_cb.Run()); } @@ -692,7 +692,7 @@ TEST_F(BindTest, Owned) { // If we don't capture, delete happens on Callback destruction/reset. // return the same value. - Callback<DeleteCounter*(void)> no_capture_cb = + Callback<DeleteCounter*()> no_capture_cb = Bind(&PolymorphicIdentity<DeleteCounter*>, Owned(counter)); ASSERT_EQ(counter, no_capture_cb.Run()); ASSERT_EQ(counter, no_capture_cb.Run()); @@ -721,7 +721,7 @@ TEST_F(BindTest, ScopedPtr) { // Tests the Passed() function's support for pointers. scoped_ptr<DeleteCounter> ptr(new DeleteCounter(&deletes)); - Callback<scoped_ptr<DeleteCounter>(void)> unused_callback = + Callback<scoped_ptr<DeleteCounter>()> unused_callback = Bind(&PassThru<scoped_ptr<DeleteCounter> >, Passed(&ptr)); EXPECT_FALSE(ptr.get()); EXPECT_EQ(0, deletes); @@ -733,7 +733,7 @@ TEST_F(BindTest, ScopedPtr) { // Tests the Passed() function's support for rvalues. deletes = 0; DeleteCounter* counter = new DeleteCounter(&deletes); - Callback<scoped_ptr<DeleteCounter>(void)> callback = + Callback<scoped_ptr<DeleteCounter>()> callback = Bind(&PassThru<scoped_ptr<DeleteCounter> >, Passed(scoped_ptr<DeleteCounter>(counter))); EXPECT_FALSE(ptr.get()); @@ -764,7 +764,7 @@ TEST_F(BindTest, UniquePtr) { // Tests the Passed() function's support for pointers. std::unique_ptr<DeleteCounter> ptr(new DeleteCounter(&deletes)); - Callback<std::unique_ptr<DeleteCounter>(void)> unused_callback = + Callback<std::unique_ptr<DeleteCounter>()> unused_callback = Bind(&PassThru<std::unique_ptr<DeleteCounter>>, Passed(&ptr)); EXPECT_FALSE(ptr.get()); EXPECT_EQ(0, deletes); @@ -776,7 +776,7 @@ TEST_F(BindTest, UniquePtr) { // Tests the Passed() function's support for rvalues. deletes = 0; DeleteCounter* counter = new DeleteCounter(&deletes); - Callback<std::unique_ptr<DeleteCounter>(void)> callback = + Callback<std::unique_ptr<DeleteCounter>()> callback = Bind(&PassThru<std::unique_ptr<DeleteCounter>>, Passed(std::unique_ptr<DeleteCounter>(counter))); EXPECT_FALSE(ptr.get()); @@ -813,7 +813,7 @@ TEST_F(BindTest, ArgumentCopies) { CopyCounter counter(&copies, &assigns); - Callback<void(void)> copy_cb = + Callback<void()> copy_cb = Bind(&VoidPolymorphic<CopyCounter>::Run, counter); EXPECT_GE(1, copies); EXPECT_EQ(0, assigns); @@ -855,10 +855,10 @@ int __stdcall StdCallFunc(int n) { // - Can bind a __fastcall function. // - Can bind a __stdcall function. TEST_F(BindTest, WindowsCallingConventions) { - Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); + Callback<int()> fastcall_cb = Bind(&FastCallFunc, 1); EXPECT_EQ(1, fastcall_cb.Run()); - Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); + Callback<int()> stdcall_cb = Bind(&StdCallFunc, 2); EXPECT_EQ(2, stdcall_cb.Run()); } #endif diff --git a/base/bind_unittest.nc b/base/bind_unittest.nc index 70c479f..10d2c80 100644 --- a/base/bind_unittest.nc +++ b/base/bind_unittest.nc @@ -29,8 +29,8 @@ class HasRef : public NoRef, public base::RefCounted<HasRef> { class Parent { public: - void AddRef(void) const {} - void Release(void) const {} + void AddRef() const {} + void Release() const {} virtual void VirtualSet() { value = kParentValue; } void NonVirtualSet() { value = kParentValue; } int value; @@ -75,7 +75,7 @@ void VoidPolymorphic1(T t) { void WontCompile() { HasRef has_ref; const HasRef* const_has_ref_ptr_ = &has_ref; - Callback<void(void)> method_to_const_cb = + Callback<void()> method_to_const_cb = Bind(&HasRef::VoidMethod0, const_has_ref_ptr_); method_to_const_cb.Run(); } @@ -87,7 +87,7 @@ void WontCompile() { // We require refcounts unless you have Unretained(). void WontCompile() { NoRef no_ref; - Callback<void(void)> no_ref_cb = + Callback<void()> no_ref_cb = Bind(&NoRef::VoidMethod0, &no_ref); no_ref_cb.Run(); } @@ -99,7 +99,7 @@ void WontCompile() { // We require refcounts unless you have Unretained(). void WontCompile() { NoRef no_ref; - Callback<void(void)> no_ref_const_cb = + Callback<void()> no_ref_const_cb = Bind(&NoRef::VoidConstMethod0, &no_ref); no_ref_const_cb.Run(); } @@ -111,7 +111,7 @@ void WontCompile() { // This is just a const-correctness check. void WontCompile() { const NoRef* const_no_ref_ptr; - Callback<NoRef*(void)> pointer_same_cb = + Callback<NoRef*()> pointer_same_cb = Bind(&PolymorphicIdentity<NoRef*>, const_no_ref_ptr); pointer_same_cb.Run(); } @@ -123,7 +123,7 @@ void WontCompile() { // This is just a const-correctness check. void WontCompile() { const NoRefChild* const_child_ptr; - Callback<NoRefParent*(void)> pointer_super_cb = + Callback<NoRefParent*()> pointer_super_cb = Bind(&PolymorphicIdentity<NoRefParent*>, const_child_ptr); pointer_super_cb.Run(); } @@ -152,7 +152,7 @@ void WontCompile() { // See comment in NCTEST_DISALLOW_NON_CONST_REF_PARAM void WontCompile() { Parent p; - Callback<int(void)> ref_cb = Bind(&UnwrapParentRef, p); + Callback<int()> ref_cb = Bind(&UnwrapParentRef, p); ref_cb.Run(); } @@ -165,7 +165,7 @@ void WontCompile() { // implicitly convert an array type to a pointer type. void WontCompile() { HasRef p[10]; - Callback<void(void)> method_bound_to_array_cb = + Callback<void()> method_bound_to_array_cb = Bind(&HasRef::VoidMethod0, p); method_bound_to_array_cb.Run(); } @@ -176,9 +176,9 @@ void WontCompile() { void WontCompile() { HasRef for_raw_ptr; int a; - Callback<void(void)> ref_count_as_raw_ptr_a = + Callback<void()> ref_count_as_raw_ptr_a = Bind(&VoidPolymorphic1<int*>, &a); - Callback<void(void)> ref_count_as_raw_ptr = + Callback<void()> ref_count_as_raw_ptr = Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr); } @@ -188,7 +188,7 @@ void WontCompile() { void WontCompile() { NoRef no_ref; WeakPtrFactory<NoRef> weak_factory(&no_ref); - Callback<int(void)> weak_ptr_with_non_void_return_type = + Callback<int()> weak_ptr_with_non_void_return_type = Bind(&NoRef::IntMethod0, weak_factory.GetWeakPtr()); weak_ptr_with_non_void_return_type.Run(); } diff --git a/base/callback.h b/base/callback.h index b13e627..3bf0008 100644 --- a/base/callback.h +++ b/base/callback.h @@ -26,7 +26,7 @@ // much like lexical closures are used in other languages. For example, it // is used in Chromium code to schedule tasks on different MessageLoops. // -// A callback with no unbound input parameters (base::Callback<void(void)>) +// A callback with no unbound input parameters (base::Callback<void()>) // is called a base::Closure. Note that this is NOT the same as what other // languages refer to as a closure -- it does not retain a reference to its // enclosing environment. @@ -48,7 +48,7 @@ // BINDING A BARE FUNCTION // // int Return5() { return 5; } -// base::Callback<int(void)> func_cb = base::Bind(&Return5); +// base::Callback<int()> func_cb = base::Bind(&Return5); // LOG(INFO) << func_cb.Run(); // Prints 5. // // BINDING A CLASS METHOD @@ -62,7 +62,7 @@ // void PrintBye() { LOG(INFO) << "bye."; } // }; // scoped_refptr<Ref> ref = new Ref(); -// base::Callback<void(void)> ref_cb = base::Bind(&Ref::Foo, ref); +// base::Callback<void()> ref_cb = base::Bind(&Ref::Foo, ref); // LOG(INFO) << ref_cb.Run(); // Prints out 3. // // By default the object must support RefCounted or you will get a compiler @@ -104,10 +104,10 @@ // calling. // // void MyFunc(int i, const std::string& str) {} -// base::Callback<void(void)> cb = base::Bind(&MyFunc, 23, "hello world"); +// base::Callback<void()> cb = base::Bind(&MyFunc, 23, "hello world"); // cb.Run(); // -// A callback with no unbound input parameters (base::Callback<void(void)>) +// A callback with no unbound input parameters (base::Callback<void()>) // is called a base::Closure. So we could have also written: // // base::Closure cb = base::Bind(&MyFunc, 23, "hello world"); @@ -175,7 +175,7 @@ // // Bound parameters are specified as arguments to Bind() and are passed to the // function. A callback with no parameters or no unbound parameters is called a -// Closure (base::Callback<void(void)> and base::Closure are the same thing). +// Closure (base::Callback<void()> and base::Closure are the same thing). // // PASSING PARAMETERS OWNED BY THE CALLBACK // @@ -363,7 +363,9 @@ struct BindState; template <typename R, typename... Args> class Callback<R(Args...)> : public internal::CallbackBase { public: - typedef R(RunType)(Args...); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef R RunType(Args...); Callback() : CallbackBase(nullptr) { } @@ -393,9 +395,9 @@ class Callback<R(Args...)> : public internal::CallbackBase { } private: - typedef R(*PolymorphicInvoke)( - internal::BindStateBase*, - typename internal::CallbackParamTraits<Args>::ForwardType...); + using PolymorphicInvoke = + R(*)(internal::BindStateBase*, + typename internal::CallbackParamTraits<Args>::ForwardType...); }; } // namespace base diff --git a/base/callback_forward.h b/base/callback_forward.h index 213023d..a9a263a 100644 --- a/base/callback_forward.h +++ b/base/callback_forward.h @@ -10,9 +10,9 @@ namespace base { template <typename Sig> class Callback; -// Syntactic sugar to make Callback<void(void)> easier to declare since it +// Syntactic sugar to make Callback<void()> easier to declare since it // will be used in a lot of APIs with delayed execution. -typedef Callback<void(void)> Closure; +using Closure = Callback<void()>; } // namespace base diff --git a/base/callback_internal.h b/base/callback_internal.h index a2adbf9..d1d8ab8 100644 --- a/base/callback_internal.h +++ b/base/callback_internal.h @@ -73,7 +73,7 @@ class BASE_EXPORT CallbackBase { // another type. It is not okay to use void*. We create a InvokeFuncStorage // that that can store our function pointer, and then cast it back to // the original type on usage. - typedef void(*InvokeFuncStorage)(void); + using InvokeFuncStorage = void(*)(); // Returns true if this callback equals |other|. |other| may be null. bool Equals(const CallbackBase& other) const; @@ -148,8 +148,8 @@ struct CallbackParamTraits template <typename T> struct CallbackParamTraitsForNonMoveOnlyType { - typedef const T& ForwardType; - typedef T StorageType; + using ForwardType = const T&; + using StorageType = T; }; // The Storage should almost be impossible to trigger unless someone manually @@ -159,8 +159,8 @@ struct CallbackParamTraitsForNonMoveOnlyType { // The ForwardType should only be used for unbound arguments. template <typename T> struct CallbackParamTraitsForNonMoveOnlyType<T&> { - typedef T& ForwardType; - typedef T StorageType; + using ForwardType = T&; + using StorageType = T; }; // Note that for array types, we implicitly add a const in the conversion. This @@ -170,15 +170,15 @@ struct CallbackParamTraitsForNonMoveOnlyType<T&> { // restriction. template <typename T, size_t n> struct CallbackParamTraitsForNonMoveOnlyType<T[n]> { - typedef const T* ForwardType; - typedef const T* StorageType; + using ForwardType = const T*; + using StorageType = const T*; }; // See comment for CallbackParamTraits<T[n]>. template <typename T> struct CallbackParamTraitsForNonMoveOnlyType<T[]> { - typedef const T* ForwardType; - typedef const T* StorageType; + using ForwardType = const T*; + using StorageType = const T*; }; // Parameter traits for movable-but-not-copyable scopers. @@ -196,8 +196,8 @@ struct CallbackParamTraitsForNonMoveOnlyType<T[]> { // function or a cast would not be usable with Callback<> or Bind(). template <typename T> struct CallbackParamTraitsForMoveOnlyType { - typedef T ForwardType; - typedef T StorageType; + using ForwardType = T; + using StorageType = T; }; // CallbackForward() is a very limited simulation of C++11's std::forward() diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc index 5daef95..1f492d4 100644 --- a/base/callback_unittest.cc +++ b/base/callback_unittest.cc @@ -15,7 +15,9 @@ namespace base { namespace { struct FakeInvoker { - typedef void(RunType)(internal::BindStateBase*); + // MSVC 2013 doesn't support Type Alias of function types. + // Revisit this after we update it to newer version. + typedef void RunType(internal::BindStateBase*); static void Run(internal::BindStateBase*) { } }; @@ -30,11 +32,11 @@ namespace internal { // chance of colliding with another instantiation and breaking the // one-definition-rule. template <> -struct BindState<void(void), void(void), FakeInvoker> +struct BindState<void(), void(), FakeInvoker> : public BindStateBase { public: BindState() : BindStateBase(&Destroy) {} - typedef FakeInvoker InvokerType; + using InvokerType = FakeInvoker; private: ~BindState() {} static void Destroy(BindStateBase* self) { @@ -43,11 +45,11 @@ struct BindState<void(void), void(void), FakeInvoker> }; template <> -struct BindState<void(void), void(void), FakeInvoker, FakeInvoker> +struct BindState<void(), void(), FakeInvoker, FakeInvoker> : public BindStateBase { public: BindState() : BindStateBase(&Destroy) {} - typedef FakeInvoker InvokerType; + using InvokerType = FakeInvoker; private: ~BindState() {} static void Destroy(BindStateBase* self) { @@ -58,10 +60,9 @@ struct BindState<void(void), void(void), FakeInvoker, FakeInvoker> namespace { -typedef internal::BindState<void(void), void(void), FakeInvoker> - FakeBindState1; -typedef internal::BindState<void(void), void(void), FakeInvoker, FakeInvoker> - FakeBindState2; +using FakeBindState1 = internal::BindState<void(), void(), FakeInvoker>; +using FakeBindState2 = + internal::BindState<void(), void(), FakeInvoker, FakeInvoker>; class CallbackTest : public ::testing::Test { public: @@ -73,15 +74,15 @@ class CallbackTest : public ::testing::Test { ~CallbackTest() override {} protected: - Callback<void(void)> callback_a_; - const Callback<void(void)> callback_b_; // Ensure APIs work with const. - Callback<void(void)> null_callback_; + Callback<void()> callback_a_; + const Callback<void()> callback_b_; // Ensure APIs work with const. + Callback<void()> null_callback_; }; // Ensure we can create unbound callbacks. We need this to be able to store // them in class members that can be initialized later. TEST_F(CallbackTest, DefaultConstruction) { - Callback<void(void)> c0; + Callback<void()> c0; Callback<void(int)> c1; Callback<void(int,int)> c2; Callback<void(int,int,int)> c3; @@ -110,13 +111,13 @@ TEST_F(CallbackTest, Equals) { EXPECT_FALSE(callback_b_.Equals(callback_a_)); // We should compare based on instance, not type. - Callback<void(void)> callback_c(new FakeBindState1()); - Callback<void(void)> callback_a2 = callback_a_; + Callback<void()> callback_c(new FakeBindState1()); + Callback<void()> callback_a2 = callback_a_; EXPECT_TRUE(callback_a_.Equals(callback_a2)); EXPECT_FALSE(callback_a_.Equals(callback_c)); // Empty, however, is always equal to empty. - Callback<void(void)> empty2; + Callback<void()> empty2; EXPECT_TRUE(null_callback_.Equals(empty2)); } diff --git a/base/callback_unittest.nc b/base/callback_unittest.nc index edf26b7..a8967b6 100644 --- a/base/callback_unittest.nc +++ b/base/callback_unittest.nc @@ -23,7 +23,7 @@ class Child : Parent { // considered distinct. void WontCompile() { Closure c1; - Callback<int(void)> c2; + Callback<int()> c2; c1.Equals(c2); } @@ -34,8 +34,8 @@ void WontCompile() { // While this is technically safe, most people aren't used to it when coding // C++ so if this is happening, it is almost certainly an error. void WontCompile() { - Callback<Parent(void)> cb_a; - Callback<Child(void)> cb_b = cb_a; + Callback<Parent()> cb_a; + Callback<Child()> cb_b = cb_a; } #elif defined(NCTEST_ASSIGNMENT_FROM_SUBTYPE) // [r"fatal error: no viable overloaded '='"] @@ -43,8 +43,8 @@ void WontCompile() { // Assignment of Callback<A> from Callback<B> if A is supertype of B. // See explanation for NCTEST_CONSTRUCTION_FROM_SUBTYPE void WontCompile() { - Callback<Parent(void)> cb_a; - Callback<Child(void)> cb_b; + Callback<Parent()> cb_a; + Callback<Child()> cb_b; cb_a = cb_b; } |