From af9d56f38ca2424591deb7f3be3c42b64f7c17ee Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Tue, 13 Jan 2015 20:32:04 +0000 Subject: [PATCH] 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 --- webrtc/base/BUILD.gn | 1 + webrtc/base/base.gyp | 1 + webrtc/base/template_util.h | 8 +- webrtc/system_wrappers/interface/scoped_ptr.h | 15 +-- .../system_wrappers/interface/template_util.h | 114 ------------------ 5 files changed, 15 insertions(+), 124 deletions(-) delete mode 100644 webrtc/system_wrappers/interface/template_util.h diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index c254571f5..8baf6de55 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -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", diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index 3444ce2f2..d2dc7008e 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -55,6 +55,7 @@ 'stringencode.h', 'stringutils.cc', 'stringutils.h', + 'template_util.h', 'thread_annotations.h', 'timeutils.cc', 'timeutils.h', diff --git a/webrtc/base/template_util.h b/webrtc/base/template_util.h index f0bf39c5f..86e541d8c 100644 --- a/webrtc/base/template_util.h +++ b/webrtc/base/template_util.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 struct integral_constant { @@ -33,7 +35,7 @@ template struct is_pointer : false_type {}; template struct is_pointer : true_type {}; template struct is_same : public false_type {}; -template struct is_same : true_type {}; +template struct is_same : true_type {}; template struct is_array : public false_type {}; template struct is_array : public true_type {}; diff --git a/webrtc/system_wrappers/interface/scoped_ptr.h b/webrtc/system_wrappers/interface/scoped_ptr.h index dc1a5a8ae..90c7b8b26 100644 --- a/webrtc/system_wrappers/interface/scoped_ptr.h +++ b/webrtc/system_wrappers/interface/scoped_ptr.h @@ -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::value), + COMPILE_ASSERT((rtc::is_convertible::value), U_ptr_must_implicitly_convert_to_T_ptr); } inline void operator()(T* ptr) const { @@ -183,12 +183,13 @@ namespace internal { template struct ShouldAbortOnSelfReset { template - static NoType Test(const typename U::AllowSelfReset*); + static rtc::internal::NoType Test(const typename U::AllowSelfReset*); template - static YesType Test(...); + static rtc::internal::YesType Test(...); - static const bool value = sizeof(Test(0)) == sizeof(YesType); + static const bool value = + sizeof(Test(0)) == sizeof(rtc::internal::YesType); }; // Minimal implementation of the core logic of scoped_ptr, suitable for @@ -350,7 +351,7 @@ class scoped_ptr { template scoped_ptr(scoped_ptr&& other) : impl_(&other.impl_) { - COMPILE_ASSERT(!webrtc::is_array::value, U_cannot_be_an_array); + COMPILE_ASSERT(!rtc::is_array::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 scoped_ptr& operator=(scoped_ptr&& rhs) { - COMPILE_ASSERT(!webrtc::is_array::value, U_cannot_be_an_array); + COMPILE_ASSERT(!rtc::is_array::value, U_cannot_be_an_array); impl_.TakeState(&rhs.impl_); return *this; } diff --git a/webrtc/system_wrappers/interface/template_util.h b/webrtc/system_wrappers/interface/template_util.h deleted file mode 100644 index 410e04cc9..000000000 --- a/webrtc/system_wrappers/interface/template_util.h +++ /dev/null @@ -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 // For size_t. - -namespace webrtc { - -// Template definitions from tr1. - -template -struct integral_constant { - static const T value = v; - typedef T value_type; - typedef integral_constant type; -}; - -template const T integral_constant::value; - -typedef integral_constant true_type; -typedef integral_constant false_type; - -template struct is_pointer : false_type {}; -template struct is_pointer : true_type {}; - -template struct is_same : public false_type {}; -template struct is_same : true_type {}; - -template struct is_array : public false_type {}; -template struct is_array : public true_type {}; -template struct is_array : public true_type {}; - -template struct is_non_const_reference : false_type {}; -template struct is_non_const_reference : true_type {}; -template struct is_non_const_reference : false_type {}; - -template struct is_void : false_type {}; -template <> struct is_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 - static YesType Test(To); - - template - static NoType Test(...); - - template - 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 - static YesType Test(void(C::*)(void)); - - template - 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 -struct is_convertible - : integral_constant( - internal::ConvertHelper::Create())) == - sizeof(internal::YesType)> { -}; - -template -struct is_class - : integral_constant(0)) == - sizeof(internal::YesType)> { -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TEMPLATE_UTIL_H_