Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Unified Diff: ui/views/controls/scroll_view_unittest.cc

Issue 2449753002: base::EmplaceUnique (Closed)
Patch Set: less weird Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/scroll_view_unittest.cc
diff --git a/ui/views/controls/scroll_view_unittest.cc b/ui/views/controls/scroll_view_unittest.cc
index 9a9b002ff84e39b2c01d718c9a8c14c90ba13f7b..6b119f547fe0b9c37bbebc94df6f42fecc53308a 100644
--- a/ui/views/controls/scroll_view_unittest.cc
+++ b/ui/views/controls/scroll_view_unittest.cc
@@ -8,6 +8,7 @@
#include "base/run_loop.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "base/tuple.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/border.h"
#include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
@@ -21,6 +22,40 @@
#include "ui/base/test/scoped_preferred_scroller_style_mac.h"
#endif
+namespace base {
+namespace internal {
+
+template <typename... Args>
+struct EmplaceUniqueResult {
+ using Tuple = std::tuple<Args...>;
+ Tuple params;
+
+ EmplaceUniqueResult(Args&&... args)
+ : params(std::forward<Args...>(args...)) {}
+
+ template <class T, std::size_t... I>
+ T* CreateNewT(IndexSequence<I...>) {
+ return new T(std::get<I>(params)...);
+ }
+
+ template <class T>
+ using UniquePtr = std::unique_ptr<T>; // Avoids a presumbmit error.
+
+ template <class T>
+ operator UniquePtr<T>() {
+ return UniquePtr<T>(CreateNewT<T>(MakeIndexSequenceForTuple<Tuple>()));
+ }
+};
+
+} // namespace internal
+
+template <typename... Args>
+typename internal::EmplaceUniqueResult<Args...> EmplaceUnique(Args&&... args) {
+ return internal::EmplaceUniqueResult<Args...>(std::forward<Args...>(args...));
+}
+
+} // namespace base
+
enum ScrollBarOrientation { HORIZONTAL, VERTICAL };
namespace views {
@@ -151,8 +186,7 @@ class ScrollViewTest : public testing::Test {
// Ensure the old scroller override is destroyed before creating a new one.
// Otherwise, the swizzlers are interleaved and restore incorrect methods.
scroller_style_.reset();
- scroller_style_ =
- base::MakeUnique<ui::test::ScopedPreferredScrollerStyle>(enabled);
+ scroller_style_ = base::EmplaceUnique(enabled);
}
private:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698