Unify the two copies of template_util.h
This patch basically deletes webrtc/base/template_util.h (which is the more outdated copy, although there are only cosmetical differences) and moves webrtc/system_wrappers/source/template_util.h to take its place. The reunified header uses the rtc namespace like the old webrtc/base/template_util.h, rather than the webrtc namespace like webrtc/system_wrappers/source/template_util.h. R=aluebs@webrtc.org, andrew@webrtc.org Review URL: https://webrtc-codereview.appspot.com/38579004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@8050 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -120,6 +120,7 @@ static_library("rtc_base_approved") {
|
||||
"stringencode.h",
|
||||
"stringutils.cc",
|
||||
"stringutils.h",
|
||||
"template_util.h",
|
||||
"thread_annotations.h",
|
||||
"timeutils.cc",
|
||||
"timeutils.h",
|
||||
|
@@ -55,6 +55,7 @@
|
||||
'stringencode.h',
|
||||
'stringutils.cc',
|
||||
'stringutils.h',
|
||||
'template_util.h',
|
||||
'thread_annotations.h',
|
||||
'timeutils.cc',
|
||||
'timeutils.h',
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
||||
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
@@ -8,6 +8,8 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// Borrowed from Chromium's src/base/template_util.h.
|
||||
|
||||
#ifndef WEBRTC_BASE_TEMPLATE_UTIL_H_
|
||||
#define WEBRTC_BASE_TEMPLATE_UTIL_H_
|
||||
|
||||
@@ -15,7 +17,7 @@
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// template definitions from tr1
|
||||
// Template definitions from tr1.
|
||||
|
||||
template<class T, T v>
|
||||
struct integral_constant {
|
||||
|
@@ -107,7 +107,7 @@
|
||||
#include "webrtc/base/compile_assert.h"
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/move.h"
|
||||
#include "webrtc/system_wrappers/interface/template_util.h"
|
||||
#include "webrtc/base/template_util.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
@@ -133,7 +133,7 @@ struct DefaultDeleter {
|
||||
// cannot convert to T*.
|
||||
enum { T_must_be_complete = sizeof(T) };
|
||||
enum { U_must_be_complete = sizeof(U) };
|
||||
COMPILE_ASSERT((webrtc::is_convertible<U*, T*>::value),
|
||||
COMPILE_ASSERT((rtc::is_convertible<U*, T*>::value),
|
||||
U_ptr_must_implicitly_convert_to_T_ptr);
|
||||
}
|
||||
inline void operator()(T* ptr) const {
|
||||
@@ -183,12 +183,13 @@ namespace internal {
|
||||
template <typename T>
|
||||
struct ShouldAbortOnSelfReset {
|
||||
template <typename U>
|
||||
static NoType Test(const typename U::AllowSelfReset*);
|
||||
static rtc::internal::NoType Test(const typename U::AllowSelfReset*);
|
||||
|
||||
template <typename U>
|
||||
static YesType Test(...);
|
||||
static rtc::internal::YesType Test(...);
|
||||
|
||||
static const bool value = sizeof(Test<T>(0)) == sizeof(YesType);
|
||||
static const bool value =
|
||||
sizeof(Test<T>(0)) == sizeof(rtc::internal::YesType);
|
||||
};
|
||||
|
||||
// Minimal implementation of the core logic of scoped_ptr, suitable for
|
||||
@@ -350,7 +351,7 @@ class scoped_ptr {
|
||||
template <typename U, typename V>
|
||||
scoped_ptr(scoped_ptr<U, V>&& other)
|
||||
: impl_(&other.impl_) {
|
||||
COMPILE_ASSERT(!webrtc::is_array<U>::value, U_cannot_be_an_array);
|
||||
COMPILE_ASSERT(!rtc::is_array<U>::value, U_cannot_be_an_array);
|
||||
}
|
||||
|
||||
// operator=. Allows assignment from a scoped_ptr rvalue for a convertible
|
||||
@@ -365,7 +366,7 @@ class scoped_ptr {
|
||||
// scoped_ptr.
|
||||
template <typename U, typename V>
|
||||
scoped_ptr& operator=(scoped_ptr<U, V>&& rhs) {
|
||||
COMPILE_ASSERT(!webrtc::is_array<U>::value, U_cannot_be_an_array);
|
||||
COMPILE_ASSERT(!rtc::is_array<U>::value, U_cannot_be_an_array);
|
||||
impl_.TakeState(&rhs.impl_);
|
||||
return *this;
|
||||
}
|
||||
|
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
// Borrowed from Chromium's src/base/template_util.h.
|
||||
|
||||
#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TEMPLATE_UTIL_H_
|
||||
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TEMPLATE_UTIL_H_
|
||||
|
||||
#include <stddef.h> // For size_t.
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// 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 {};
|
||||
|
||||
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_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)> {
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TEMPLATE_UTIL_H_
|
Reference in New Issue
Block a user