Skip to content

Commit

Permalink
Replace typedef with using for Callback/Bind related files
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
tzik authored and Commit bot committed Dec 19, 2015
1 parent 7131453 commit 3bc7779
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 142 deletions.
15 changes: 7 additions & 8 deletions base/bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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...));
Expand Down
36 changes: 19 additions & 17 deletions base/bind_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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>*);
Expand Down Expand Up @@ -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*);
Expand Down Expand Up @@ -390,49 +390,49 @@ 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();
}
};

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();
}
};

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();
}
};

template <typename T>
struct UnwrapTraits<PassedWrapper<T> > {
typedef T ForwardType;
using ForwardType = T;
static T Unwrap(PassedWrapper<T>& o) {
return o.Pass();
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
32 changes: 19 additions & 13 deletions base/bind_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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...);
};


Expand All @@ -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;
};


Expand Down
8 changes: 6 additions & 2 deletions base/bind_internal_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 3bc7779

Please sign in to comment.