diff --git a/rtc_base/containers/BUILD.gn b/rtc_base/containers/BUILD.gn index f303e706e4..621b6122a3 100644 --- a/rtc_base/containers/BUILD.gn +++ b/rtc_base/containers/BUILD.gn @@ -10,14 +10,11 @@ import("../../webrtc.gni") rtc_library("flat_containers_internal") { sources = [ - "as_const.h", "flat_tree.cc", "flat_tree.h", "identity.h", "invoke.h", "move_only_int.h", - "not_fn.h", - "void_t.h", ] deps = [ "..:checks", diff --git a/rtc_base/containers/as_const.h b/rtc_base/containers/as_const.h deleted file mode 100644 index a41b3bc378..0000000000 --- a/rtc_base/containers/as_const.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -// This implementation is borrowed from Chromium. - -#ifndef RTC_BASE_CONTAINERS_AS_CONST_H_ -#define RTC_BASE_CONTAINERS_AS_CONST_H_ - -#include - -namespace webrtc { - -// C++14 implementation of C++17's std::as_const(): -// https://en.cppreference.com/w/cpp/utility/as_const -template -constexpr std::add_const_t& as_const(T& t) noexcept { - return t; -} - -template -void as_const(const T&& t) = delete; - -} // namespace webrtc - -#endif // RTC_BASE_CONTAINERS_AS_CONST_H_ diff --git a/rtc_base/containers/flat_map_unittest.cc b/rtc_base/containers/flat_map_unittest.cc index 8317f6a340..98846a0206 100644 --- a/rtc_base/containers/flat_map_unittest.cc +++ b/rtc_base/containers/flat_map_unittest.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include "rtc_base/containers/move_only_int.h" @@ -220,7 +221,7 @@ TEST(FlatMap, AtFunction) { EXPECT_EQ("b", m.at(2)); // Const reference works. - const std::string& const_ref = webrtc::as_const(m).at(1); + const std::string& const_ref = std::as_const(m).at(1); EXPECT_EQ("a", const_ref); // Reference works, can operate on the string. @@ -234,7 +235,7 @@ TEST(FlatMap, AtFunction) { // Heterogeneous look-up works. flat_map m2 = {{"a", 1}, {"b", 2}}; EXPECT_EQ(1, m2.at(absl::string_view("a"))); - EXPECT_EQ(2, webrtc::as_const(m2).at(absl::string_view("b"))); + EXPECT_EQ(2, std::as_const(m2).at(absl::string_view("b"))); } // insert_or_assign(K&&, M&&) diff --git a/rtc_base/containers/flat_tree.h b/rtc_base/containers/flat_tree.h index c79b62b16f..480784ced4 100644 --- a/rtc_base/containers/flat_tree.h +++ b/rtc_base/containers/flat_tree.h @@ -21,9 +21,6 @@ #include "absl/algorithm/container.h" #include "rtc_base/checks.h" -#include "rtc_base/containers/as_const.h" -#include "rtc_base/containers/not_fn.h" -#include "rtc_base/containers/void_t.h" #include "rtc_base/system/no_unique_address.h" namespace webrtc { @@ -44,7 +41,7 @@ constexpr bool is_sorted_and_unique(const Range& range, Comp comp) { // Being unique implies that there are no adjacent elements that // compare equal. So this checks that each element is strictly less // than the element after it. - return absl::c_adjacent_find(range, webrtc::not_fn(comp)) == std::end(range); + return absl::c_adjacent_find(range, std::not_fn(comp)) == std::end(range); } // This is a convenience trait inheriting from std::true_type if Iterator is at @@ -58,7 +55,7 @@ using is_multipass = template struct IsTransparentCompare : std::false_type {}; template -struct IsTransparentCompare> +struct IsTransparentCompare> : std::true_type {}; // Helper inspired by C++20's std::to_array to convert a C-style array to a @@ -543,7 +540,7 @@ class flat_tree { std::stable_sort(first, last, value_comp()); // lhs is already <= rhs due to sort, therefore !(lhs < rhs) <=> lhs == rhs. - auto equal_comp = webrtc::not_fn(value_comp()); + auto equal_comp = std::not_fn(value_comp()); erase(std::unique(first, last, equal_comp), last); } @@ -946,7 +943,7 @@ template template auto flat_tree::find(const K& key) -> iterator { - return const_cast_it(webrtc::as_const(*this).find(key)); + return const_cast_it(std::as_const(*this).find(key)); } template @@ -969,7 +966,7 @@ template template auto flat_tree::equal_range( const K& key) -> std::pair { - auto res = webrtc::as_const(*this).equal_range(key); + auto res = std::as_const(*this).equal_range(key); return {const_cast_it(res.first), const_cast_it(res.second)}; } @@ -990,7 +987,7 @@ template template auto flat_tree::lower_bound( const K& key) -> iterator { - return const_cast_it(webrtc::as_const(*this).lower_bound(key)); + return const_cast_it(std::as_const(*this).lower_bound(key)); } template @@ -1011,7 +1008,7 @@ template template auto flat_tree::upper_bound( const K& key) -> iterator { - return const_cast_it(webrtc::as_const(*this).upper_bound(key)); + return const_cast_it(std::as_const(*this).upper_bound(key)); } template diff --git a/rtc_base/containers/not_fn.h b/rtc_base/containers/not_fn.h deleted file mode 100644 index 39cfd2763c..0000000000 --- a/rtc_base/containers/not_fn.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -// This implementation is borrowed from Chromium. - -#ifndef RTC_BASE_CONTAINERS_NOT_FN_H_ -#define RTC_BASE_CONTAINERS_NOT_FN_H_ - -#include -#include - -#include "rtc_base/containers/invoke.h" - -namespace webrtc { - -namespace not_fn_internal { - -template -struct NotFnImpl { - F f; - - template - constexpr decltype(auto) operator()(Args&&... args) & noexcept { - return !webrtc::invoke(f, std::forward(args)...); - } - - template - constexpr decltype(auto) operator()(Args&&... args) const& noexcept { - return !webrtc::invoke(f, std::forward(args)...); - } - - template - constexpr decltype(auto) operator()(Args&&... args) && noexcept { - return !webrtc::invoke(std::move(f), std::forward(args)...); - } - - template - constexpr decltype(auto) operator()(Args&&... args) const&& noexcept { - return !webrtc::invoke(std::move(f), std::forward(args)...); - } -}; - -} // namespace not_fn_internal - -// Implementation of C++17's std::not_fn. -// -// Reference: -// - https://en.cppreference.com/w/cpp/utility/functional/not_fn -// - https://wg21.link/func.not.fn -template -constexpr not_fn_internal::NotFnImpl> not_fn(F&& f) { - return {std::forward(f)}; -} - -} // namespace webrtc - -#endif // RTC_BASE_CONTAINERS_NOT_FN_H_ diff --git a/rtc_base/containers/void_t.h b/rtc_base/containers/void_t.h deleted file mode 100644 index 149fc70c11..0000000000 --- a/rtc_base/containers/void_t.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -// This implementation is borrowed from Chromium. - -#ifndef RTC_BASE_CONTAINERS_VOID_T_H_ -#define RTC_BASE_CONTAINERS_VOID_T_H_ - -namespace webrtc { -namespace void_t_internal { -// Implementation detail of webrtc::void_t below. -template -struct make_void { - using type = void; -}; - -} // namespace void_t_internal - -// webrtc::void_t is an implementation of std::void_t from C++17. -// -// We use `webrtc::void_t_internal::make_void` as a helper struct to avoid a -// C++14 defect: -// http://en.cppreference.com/w/cpp/types/void_t -// http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558 -template -using void_t = typename ::webrtc::void_t_internal::make_void::type; -} // namespace webrtc - -#endif // RTC_BASE_CONTAINERS_VOID_T_H_