From 90401e3fbad42bfae2e7c1f462a01f2f1c8c086a Mon Sep 17 00:00:00 2001 From: Andi-Bogdan Postelnicu Date: Fri, 24 Mar 2023 18:55:40 +0000 Subject: [PATCH] Bug 1276351 - remove unused mozilla::tuple. r=sergesanspaille Differential Revision: https://phabricator.services.mozilla.com/D173299 --- mfbt/Tuple.h | 515 ------------------ mfbt/moz.build | 1 - mfbt/tests/TestTuple.cpp | 362 ------------ mfbt/tests/moz.build | 1 - .../dllservices/tests/TestDllInterceptor.cpp | 2 +- xpcom/base/TupleCycleCollection.h | 31 -- xpcom/base/moz.build | 1 - xpcom/threads/nsThreadUtils.h | 16 +- 8 files changed, 7 insertions(+), 922 deletions(-) delete mode 100644 mfbt/Tuple.h delete mode 100644 mfbt/tests/TestTuple.cpp delete mode 100644 xpcom/base/TupleCycleCollection.h diff --git a/mfbt/Tuple.h b/mfbt/Tuple.h deleted file mode 100644 index 7fec059ef967..000000000000 --- a/mfbt/Tuple.h +++ /dev/null @@ -1,515 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* A variadic tuple class. */ - -#ifndef mozilla_Tuple_h -#define mozilla_Tuple_h - -#include - -#include -#include - -#include "mozilla/CompactPair.h" -#include "mozilla/TemplateLib.h" - -namespace mozilla { - -namespace detail { - -/* - * A helper class that allows passing around multiple variadic argument lists - * by grouping them. - */ -template -struct Group; - -/* - * CheckConvertibility checks whether each type in a source pack of types - * is convertible to the corresponding type in a target pack of types. - * - * It is intended to be invoked like this: - * CheckConvertibility, Group> - * 'Group' is used to separate types in the two packs (otherwise if we just - * wrote 'CheckConvertibility -struct CheckConvertibilityImpl; - -template -struct CheckConvertibilityImpl : std::false_type {}; - -template -struct CheckConvertibilityImpl, Group, - true> - : std::integral_constant< - bool, - tl::And...>::value> { -}; - -template -struct CheckConvertibility; - -template -struct CheckConvertibility, Group> - : CheckConvertibilityImpl, Group, - sizeof...(SourceTypes) == - sizeof...(TargetTypes)> {}; - -/* - * Helper type for Tie(args...) to allow ignoring specific elements - * during Tie unpacking. Supports assignment from any type. - * - * Not for direct usage; instead, use mozilla::Ignore in calls to Tie. - */ -struct IgnoreImpl { - template - constexpr const IgnoreImpl& operator=(const T&) const { - return *this; - } -}; - -/* - * TupleImpl is a helper class used to implement mozilla::Tuple. - * It represents one node in a recursive inheritance hierarchy. - * 'Index' is the 0-based index of the tuple element stored in this node; - * 'Elements...' are the types of the elements stored in this node and its - * base classes. - * - * Example: - * Tuple inherits from - * TupleImpl<0, int, float, char>, which stores the 'int' and inherits from - * TupleImpl<1, float, char>, which stores the 'float' and inherits from - * TupleImpl<2, char>, which stores the 'char' and inherits from - * TupleImpl<3>, which stores nothing and terminates the recursion. - * - * The purpose of the 'Index' parameter is to allow efficient index-based - * access to a tuple element: given a tuple, and an index 'I' that we wish to - * access, we can cast the tuple to the base which stores the I'th element - * by performing template argument deduction against 'TupleImpl', - * where 'I' is specified explicitly and 'E...' is deduced (this is what the - * non-member 'Get(t)' function does). - * - * This implementation strategy is borrowed from libstdc++'s std::tuple - * implementation. - */ -template -struct TupleImpl; - -/* - * The base case of the inheritance recursion (and also the implementation - * of an empty tuple). - */ -template -struct TupleImpl { - bool operator==(const TupleImpl& aOther) const { return true; } - - template - void ForEach(const F& aFunc) const {} -}; - -/* - * One node of the recursive inheritance hierarchy. It stores the element at - * index 'Index' of a tuple, of type 'HeadT', and inherits from the nodes - * that store the remaining elements, of types 'TailT...'. - */ -template -struct TupleImpl - : public TupleImpl { - typedef TupleImpl Base; - - // Accessors for the head and the tail. - // These are static, because the intended usage is for the caller to, - // given a tuple, obtain the type B of the base class which stores the - // element of interest, and then call B::Head(tuple) to access it. - // (Tail() is mostly for internal use, but is exposed for consistency.) - static HeadT& Head(TupleImpl& aTuple) { return aTuple.mHead; } - static const HeadT& Head(const TupleImpl& aTuple) { return aTuple.mHead; } - static Base& Tail(TupleImpl& aTuple) { return aTuple; } - static const Base& Tail(const TupleImpl& aTuple) { return aTuple; } - - TupleImpl() : Base(), mHead() {} - - // Construct from const references to the elements. - explicit TupleImpl(const HeadT& aHead, const TailT&... aTail) - : Base(aTail...), mHead(aHead) {} - - // Construct from objects that are convertible to the elements. - // This constructor is enabled only when the argument types are actually - // convertible to the element types, otherwise it could become a better - // match for certain invocations than the copy constructor. - template < - typename OtherHeadT, typename... OtherTailT, - typename = std::enable_if_t, Group>::value>> - explicit TupleImpl(OtherHeadT&& aHead, OtherTailT&&... aTail) - : Base(std::forward(aTail)...), - mHead(std::forward(aHead)) {} - - // Copy and move constructors. - // We'd like to use '= default' to implement these, but MSVC 2013's support - // for '= default' is incomplete and this doesn't work. - TupleImpl(const TupleImpl& aOther) - : Base(Tail(aOther)), mHead(Head(aOther)) {} - TupleImpl(TupleImpl&& aOther) - : Base(std::move(Tail(aOther))), - mHead(std::forward(Head(aOther))) {} - - // Assign from a tuple whose elements are convertible to the elements - // of this tuple. - template > - TupleImpl& operator=(const TupleImpl& aOther) { - typedef TupleImpl OtherT; - Head(*this) = OtherT::Head(aOther); - Tail(*this) = OtherT::Tail(aOther); - return *this; - } - template > - TupleImpl& operator=(TupleImpl&& aOther) { - typedef TupleImpl OtherT; - Head(*this) = std::move(OtherT::Head(aOther)); - Tail(*this) = std::move(OtherT::Tail(aOther)); - return *this; - } - - // Copy and move assignment operators. - TupleImpl& operator=(const TupleImpl& aOther) { - Head(*this) = Head(aOther); - Tail(*this) = Tail(aOther); - return *this; - } - TupleImpl& operator=(TupleImpl&& aOther) { - Head(*this) = std::move(Head(aOther)); - Tail(*this) = std::move(Tail(aOther)); - return *this; - } - bool operator==(const TupleImpl& aOther) const { - return Head(*this) == Head(aOther) && Tail(*this) == Tail(aOther); - } - - template - void ForEach(const F& aFunc) const& { - aFunc(Head(*this)); - Tail(*this).ForEach(aFunc); - } - - template - void ForEach(const F& aFunc) & { - aFunc(Head(*this)); - Tail(*this).ForEach(aFunc); - } - - template - void ForEach(const F& aFunc) && { - aFunc(std::move(Head(*this))); - std::move(Tail(*this)).ForEach(aFunc); - } - - private: - HeadT mHead; // The element stored at this index in the tuple. -}; - -} // namespace detail - -/** - * Tuple is a class that stores zero or more objects, whose types are specified - * as template parameters. It can be thought of as a generalization of - * std::pair, (which can be thought of as a 2-tuple). - * - * Tuple allows index-based access to its elements (with the index having to be - * known at compile time) via the non-member function 'Get(tuple)'. - */ -template -class Tuple : public detail::TupleImpl<0, Elements...> { - typedef detail::TupleImpl<0, Elements...> Impl; - - public: - // The constructors and assignment operators here are simple wrappers - // around those in TupleImpl. - - Tuple() : Impl() {} - explicit Tuple(const Elements&... aElements) : Impl(aElements...) {} - // Here, we can't just use 'typename... OtherElements' because MSVC will give - // a warning "C4520: multiple default constructors specified" (even if no one - // actually instantiates the constructor with an empty parameter pack - - // that's probably a bug) and we compile with warnings-as-errors. - template , - detail::Group>::value>> - explicit Tuple(OtherHead&& aHead, OtherTail&&... aTail) - : Impl(std::forward(aHead), - std::forward(aTail)...) {} - Tuple(const Tuple& aOther) : Impl(aOther) {} - Tuple(Tuple&& aOther) : Impl(std::move(aOther)) {} - - template > - Tuple& operator=(const Tuple& aOther) { - static_cast(*this) = aOther; - return *this; - } - template > - Tuple& operator=(Tuple&& aOther) { - static_cast(*this) = std::move(aOther); - return *this; - } - Tuple& operator=(const Tuple& aOther) { - static_cast(*this) = aOther; - return *this; - } - Tuple& operator=(Tuple&& aOther) { - static_cast(*this) = std::move(aOther); - return *this; - } - bool operator==(const Tuple& aOther) const { - return static_cast(*this) == static_cast(aOther); - } -}; - -/** - * Specialization of Tuple for two elements. - * This is created to support construction and assignment from a CompactPair or - * std::pair. - */ -template -class Tuple : public detail::TupleImpl<0, A, B> { - typedef detail::TupleImpl<0, A, B> Impl; - - public: - // The constructors and assignment operators here are simple wrappers - // around those in TupleImpl. - - Tuple() : Impl() {} - explicit Tuple(const A& aA, const B& aB) : Impl(aA, aB) {} - template , detail::Group>::value>> - explicit Tuple(AArg&& aA, BArg&& aB) - : Impl(std::forward(aA), std::forward(aB)) {} - Tuple(const Tuple& aOther) : Impl(aOther) {} - Tuple(Tuple&& aOther) : Impl(std::move(aOther)) {} - explicit Tuple(const CompactPair& aOther) - : Impl(aOther.first(), aOther.second()) {} - explicit Tuple(CompactPair&& aOther) - : Impl(std::forward(aOther.first()), - std::forward(aOther.second())) {} - explicit Tuple(const std::pair& aOther) - : Impl(aOther.first, aOther.second) {} - explicit Tuple(std::pair&& aOther) - : Impl(std::forward(aOther.first), std::forward(aOther.second)) {} - - template - Tuple& operator=(const Tuple& aOther) { - static_cast(*this) = aOther; - return *this; - } - template - Tuple& operator=(Tuple&& aOther) { - static_cast(*this) = std::move(aOther); - return *this; - } - Tuple& operator=(const Tuple& aOther) { - static_cast(*this) = aOther; - return *this; - } - Tuple& operator=(Tuple&& aOther) { - static_cast(*this) = std::move(aOther); - return *this; - } - template - Tuple& operator=(const CompactPair& aOther) { - Impl::Head(*this) = aOther.first(); - Impl::Tail(*this).Head(*this) = aOther.second(); - return *this; - } - template - Tuple& operator=(CompactPair&& aOther) { - Impl::Head(*this) = std::forward(aOther.first()); - Impl::Tail(*this).Head(*this) = std::forward(aOther.second()); - return *this; - } - template - Tuple& operator=(const std::pair& aOther) { - Impl::Head(*this) = aOther.first; - Impl::Tail(*this).Head(*this) = aOther.second; - return *this; - } - template - Tuple& operator=(std::pair&& aOther) { - Impl::Head(*this) = std::forward(aOther.first); - Impl::Tail(*this).Head(*this) = std::forward(aOther.second); - return *this; - } -}; - -/** - * Specialization of Tuple for zero arguments. - * This is necessary because if the primary template were instantiated with - * an empty parameter pack, the 'Tuple(Elements...)' constructors would - * become illegal overloads of the default constructor. - */ -template <> -class Tuple<> {}; - -namespace detail { - -/* - * Helper functions for implementing Get(tuple). - * These functions take a TupleImpl, with Index being - * explicitly specified, and Elements being deduced. By passing a Tuple - * object as argument, template argument deduction will do its magic and - * cast the tuple to the base class which stores the element at Index. - */ - -// Const reference version. -template -auto TupleGetHelper(TupleImpl& aTuple) - -> decltype(TupleImpl::Head(aTuple)) { - return TupleImpl::Head(aTuple); -} - -// Non-const reference version. -template -auto TupleGetHelper(const TupleImpl& aTuple) - -> decltype(TupleImpl::Head(aTuple)) { - return TupleImpl::Head(aTuple); -} - -} // namespace detail - -/** - * Index-based access to an element of a tuple. - * The syntax is Get(tuple). The index is zero-based. - * - * Example: - * - * Tuple t; - * ... - * float f = Get<1>(t); - */ - -// Non-const reference version. -template -auto Get(Tuple& aTuple) - -> decltype(detail::TupleGetHelper(aTuple)) { - return detail::TupleGetHelper(aTuple); -} - -// Const reference version. -template -auto Get(const Tuple& aTuple) - -> decltype(detail::TupleGetHelper(aTuple)) { - return detail::TupleGetHelper(aTuple); -} - -// Rvalue reference version. -template -auto Get(Tuple&& aTuple) - -> decltype(std::move(mozilla::Get(aTuple))) { - // We need a 'mozilla::' qualification here to avoid - // name lookup only finding the current function. - return std::move(mozilla::Get(aTuple)); -} - -/** - * Helpers which call a function for each member of the tuple in turn. This will - * typically be used with a lambda function with an `auto&` argument: - * - * Tuple> tuple{a, b, c}; - * - * ForEach(tuple, [](auto& aElem) { - * aElem = nullptr; - * }); - */ - -template -inline void ForEach(const Tuple<>& aTuple, const F& aFunc) {} - -template -inline void ForEach(Tuple<>& aTuple, const F& aFunc) {} - -template -void ForEach(const Tuple& aTuple, const F& aFunc) { - aTuple.ForEach(aFunc); -} - -template -void ForEach(Tuple& aTuple, const F& aFunc) { - aTuple.ForEach(aFunc); -} - -template -void ForEach(Tuple&& aTuple, const F& aFunc) { - std::forward>(aTuple).ForEach(aFunc); -} - -/** - * A convenience function for constructing a tuple out of a sequence of - * values without specifying the type of the tuple. - * The type of the tuple is deduced from the types of its elements. - * - * Example: - * - * auto tuple = MakeTuple(42, 0.5f, 'c'); // has type Tuple - */ -template -inline Tuple...> MakeTuple(Elements&&... aElements) { - return Tuple...>(std::forward(aElements)...); -} - -/** - * A helper placholder to allow ignoring specific elements during Tie unpacking. - * Can be used with any type and any number of elements in a call to Tie. - * - * Usage of Ignore with Tie is equivalent to using std::ignore with - * std::tie. - * - * Example: - * - * int i; - * float f; - * char c; - * Tie(i, Ignore, f, c, Ignore) = FunctionThatReturnsATuple(); - */ -constexpr detail::IgnoreImpl Ignore; - -/** - * A convenience function for constructing a tuple of references to a - * sequence of variables. Since assignments to the elements of the tuple - * "go through" to the referenced variables, this can be used to "unpack" - * a tuple into individual variables. - * - * Example: - * - * int i; - * float f; - * char c; - * Tie(i, f, c) = FunctionThatReturnsATuple(); - */ -template -inline Tuple Tie(Elements&... aVariables) { - return Tuple(aVariables...); -} - -} // namespace mozilla - -#endif /* mozilla_Tuple_h */ diff --git a/mfbt/moz.build b/mfbt/moz.build index 154ccb8c49db..2ae2e76ac557 100644 --- a/mfbt/moz.build +++ b/mfbt/moz.build @@ -113,7 +113,6 @@ EXPORTS.mozilla = [ "ThreadSafety.h", "ThreadSafeWeakPtr.h", "ToString.h", - "Tuple.h", "TypedEnumBits.h", "Types.h", "TypeTraits.h", diff --git a/mfbt/tests/TestTuple.cpp b/mfbt/tests/TestTuple.cpp deleted file mode 100644 index 4e20101972b4..000000000000 --- a/mfbt/tests/TestTuple.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include -#include - -#include "mozilla/Assertions.h" -#include "mozilla/CompactPair.h" -#include "mozilla/Tuple.h" -#include "mozilla/UniquePtr.h" -#include "mozilla/Unused.h" - -using mozilla::CompactPair; -using mozilla::Get; -using mozilla::MakeTuple; -using mozilla::MakeUnique; -using mozilla::Tie; -using mozilla::Tuple; -using mozilla::UniquePtr; -using mozilla::Unused; -using std::pair; - -#define CHECK(c) \ - do { \ - bool cond = !!(c); \ - MOZ_RELEASE_ASSERT(cond, "Failed assertion: " #c); \ - } while (false) - -// The second argument is the expected type. It's variadic to allow the -// type to contain commas. -#define CHECK_TYPE(expression, ...) \ - static_assert(std::is_same_v, \ - "Type mismatch!") - -struct ConvertibleToInt { - operator int() const { return 42; } -}; - -static void TestConstruction() { - // Default construction - Tuple<> a; - Unused << a; - Tuple b; - Unused << b; - - // Construction from elements - int x = 1, y = 1; - Tuple c{x, y}; - Tuple d{x, y}; - x = 42; - y = 42; - CHECK(Get<0>(c) == 1); - CHECK(Get<1>(c) == 1); - CHECK(Get<0>(d) == 42); - CHECK(Get<1>(d) == 42); - - // Construction from objects convertible to the element types - Tuple e{1.0, ConvertibleToInt{}}; - - // Copy construction - Tuple x1; - Tuple x2{x1}; - - Tuple f(c); - CHECK(Get<0>(f) == 1); - CHECK(Get<0>(f) == 1); - - // Move construction - Tuple> g{MakeUnique(42)}; - Tuple> h{std::move(g)}; - CHECK(Get<0>(g) == nullptr); - CHECK(*Get<0>(h) == 42); -} - -static void TestConstructionFromMozPair() { - // Construction from elements - int x = 1, y = 1; - CompactPair a{x, y}; - CompactPair b{x, y}; - Tuple c(a); - Tuple d(b); - x = 42; - y = 42; - CHECK(Get<0>(c) == 1); - CHECK(Get<1>(c) == 1); - CHECK(Get<0>(d) == 42); - CHECK(Get<1>(d) == 42); -} - -static void TestConstructionFromStdPair() { - // Construction from elements - int x = 1, y = 1; - pair a{x, y}; - pair b{x, y}; - Tuple c(a); - Tuple d(b); - x = 42; - y = 42; - CHECK(Get<0>(c) == 1); - CHECK(Get<1>(c) == 1); - CHECK(Get<0>(d) == 42); - CHECK(Get<1>(d) == 42); -} - -static void TestAssignment() { - // Copy assignment - Tuple a{0}; - Tuple b{42}; - a = b; - CHECK(Get<0>(a) == 42); - - // Assignment to reference member - int i = 0; - int j = 42; - Tuple c{i}; - Tuple d{j}; - c = d; - CHECK(i == 42); - - // Move assignment - Tuple> e{MakeUnique(0)}; - Tuple> f{MakeUnique(42)}; - e = std::move(f); - CHECK(*Get<0>(e) == 42); - CHECK(Get<0>(f) == nullptr); -} - -static void TestAssignmentFromMozPair() { - // Copy assignment - Tuple a{0, 0}; - CompactPair b{42, 42}; - a = b; - CHECK(Get<0>(a) == 42); - CHECK(Get<1>(a) == 42); - - // Assignment to reference member - int i = 0; - int j = 0; - int k = 42; - Tuple c{i, j}; - CompactPair d{k, k}; - c = d; - CHECK(i == 42); - CHECK(j == 42); - - // Move assignment - Tuple, UniquePtr> e{MakeUnique(0), - MakeUnique(0)}; - CompactPair, UniquePtr> f{MakeUnique(42), - MakeUnique(42)}; - e = std::move(f); - CHECK(*Get<0>(e) == 42); - CHECK(*Get<1>(e) == 42); - CHECK(f.first() == nullptr); - CHECK(f.second() == nullptr); -} - -static void TestAssignmentFromStdPair() { - // Copy assignment - Tuple a{0, 0}; - pair b{42, 42}; - a = b; - CHECK(Get<0>(a) == 42); - CHECK(Get<1>(a) == 42); - - // Assignment to reference member - int i = 0; - int j = 0; - int k = 42; - Tuple c{i, j}; - pair d{k, k}; - c = d; - CHECK(i == 42); - CHECK(j == 42); - - // Move assignment. - Tuple, UniquePtr> e{MakeUnique(0), - MakeUnique(0)}; - // XXX: On some platforms std::pair doesn't support move constructor. - pair, UniquePtr> f; - f.first = MakeUnique(42); - f.second = MakeUnique(42); - - e = std::move(f); - CHECK(*Get<0>(e) == 42); - CHECK(*Get<1>(e) == 42); - CHECK(f.first == nullptr); - CHECK(f.second == nullptr); -} - -static void TestGet() { - int x = 1; - int y = 2; - int z = 3; - Tuple tuple(x, y, z); - - // Using Get<>() to read elements - CHECK(Get<0>(tuple) == 1); - CHECK(Get<1>(tuple) == 2); - CHECK(Get<2>(tuple) == 3); - - // Using Get<>() to write to elements - Get<0>(tuple) = 41; - CHECK(Get<0>(tuple) == 41); - - // Writing through reference elements - Get<1>(tuple) = 42; - CHECK(Get<1>(tuple) == 42); - CHECK(y == 42); -} - -static void TestMakeTuple() { - auto tuple = MakeTuple(42, 0.5f, 'c'); - CHECK_TYPE(tuple, Tuple); - CHECK(Get<0>(tuple) == 42); - CHECK(Get<1>(tuple) == 0.5f); - CHECK(Get<2>(tuple) == 'c'); - - // Make sure we don't infer the type to be Tuple. - int x = 1; - auto tuple2 = MakeTuple(x); - CHECK_TYPE(tuple2, Tuple); - x = 2; - CHECK(Get<0>(tuple2) == 1); -} - -static bool TestTieMozPair() { - int i; - float f; - char c; - Tuple rhs1(42, 0.5f, 'c'); - Tie(i, f, c) = rhs1; - CHECK(i == Get<0>(rhs1)); - CHECK(f == Get<1>(rhs1)); - CHECK(c == Get<2>(rhs1)); - // Test conversions - Tuple rhs2(ConvertibleToInt(), 0.7f, - 'd'); - Tie(i, f, c) = rhs2; - CHECK(i == Get<0>(rhs2)); - CHECK(f == Get<1>(rhs2)); - CHECK(c == Get<2>(rhs2)); - - // Test Pair - CompactPair rhs3(42, 1.5f); - Tie(i, f) = rhs3; - CHECK(i == rhs3.first()); - CHECK(f == rhs3.second()); - - return true; -} - -static bool TestTie() { - int i; - float f; - char c; - Tuple rhs1(42, 0.5f, 'c'); - Tie(i, f, c) = rhs1; - CHECK(i == Get<0>(rhs1)); - CHECK(f == Get<1>(rhs1)); - CHECK(c == Get<2>(rhs1)); - // Test conversions - Tuple rhs2(ConvertibleToInt(), 0.7f, - 'd'); - Tie(i, f, c) = rhs2; - CHECK(i == Get<0>(rhs2)); - CHECK(f == Get<1>(rhs2)); - CHECK(c == Get<2>(rhs2)); - - // Test Pair - pair rhs3(42, 1.5f); - Tie(i, f) = rhs3; - CHECK(i == rhs3.first); - CHECK(f == rhs3.second); - - return true; -} - -static bool TestTieIgnore() { - int i; - char c; - Tuple rhs1(42, 0.5f, 'c'); - - Tie(i, mozilla::Ignore, c) = rhs1; - - CHECK(i == Get<0>(rhs1)); - CHECK(c == Get<2>(rhs1)); - - return true; -} - -template -static void CheckForEachCall(const Tuple& aTuple, - F&& CallForEach) { - constexpr std::size_t tupleSize = sizeof...(Elements); - - Tuple checkResult; - std::size_t i = 0; - auto createResult = [&](auto& aElem) { - static_assert(tupleSize == 3, - "Need to deal with more/less cases in the switch below"); - - CHECK(i < tupleSize); - switch (i) { - case 0: - Get<0>(checkResult) = aElem; - break; - case 1: - Get<1>(checkResult) = aElem; - break; - case 2: - Get<2>(checkResult) = aElem; - break; - } - ++i; - }; - - CallForEach(aTuple, createResult); - - CHECK(checkResult == aTuple); -} - -static bool TestForEach() { - Tuple tuple = MakeTuple(42, 0.5f, 'c'); - - CheckForEachCall( - tuple, [](auto& aTuple, auto&& aLambda) { aTuple.ForEach(aLambda); }); - - CheckForEachCall( - tuple, [](auto& aTuple, auto&& aLambda) { ForEach(aTuple, aLambda); }); - - CheckForEachCall(tuple, [](auto& aTuple, auto&& aLambda) { - const decltype(aTuple)& constTuple = aTuple; - constTuple.ForEach(aLambda); - }); - - CheckForEachCall(tuple, [](auto& aTuple, auto&& aLambda) { - const decltype(aTuple)& constTuple = aTuple; - ForEach(constTuple, aLambda); - }); - - return true; -} - -int main() { - TestConstruction(); - TestConstructionFromMozPair(); - TestConstructionFromStdPair(); - TestAssignment(); - TestAssignmentFromMozPair(); - TestAssignmentFromStdPair(); - TestGet(); - TestMakeTuple(); - TestTie(); - TestTieIgnore(); - TestTieMozPair(); - TestForEach(); - return 0; -} diff --git a/mfbt/tests/moz.build b/mfbt/tests/moz.build index 510b3a1d2d81..888a340a8a6f 100644 --- a/mfbt/tests/moz.build +++ b/mfbt/tests/moz.build @@ -62,7 +62,6 @@ CppUnitTests( "TestSplayTree", "TestTemplateLib", "TestTextUtils", - "TestTuple", "TestTypedEnum", "TestTypeTraits", "TestUniquePtr", diff --git a/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp b/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp index 216d6d66fd90..a69e00743153 100644 --- a/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp +++ b/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp @@ -118,7 +118,7 @@ template , size_t... Indices> decltype(auto) Apply(OrigFuncT& aFunc, ArgTuple&& aArgs, std::index_sequence) { - return aFunc(std::get(std::forward(aArgs))...); + return std::apply(aFunc, aArgs); } #define DEFINE_TEST_FUNCTION(calling_convention) \ diff --git a/xpcom/base/TupleCycleCollection.h b/xpcom/base/TupleCycleCollection.h deleted file mode 100644 index 215855fdd870..000000000000 --- a/xpcom/base/TupleCycleCollection.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef TupleCycleCollection_h -#define TupleCycleCollection_h - -#include "mozilla/Tuple.h" -#include "nsCycleCollectionNoteChild.h" - -class nsCycleCollectionTraversalCallback; - -template -inline void ImplCycleCollectionUnlink(mozilla::Tuple& aField) { - ForEach(aField, [](auto& aElem) { ImplCycleCollectionUnlink(aElem); }); -} - -template -inline void ImplCycleCollectionTraverse( - nsCycleCollectionTraversalCallback& aCallback, - mozilla::Tuple& aField, const char* aName, - uint32_t aFlags = 0) { - aFlags |= CycleCollectionEdgeNameArrayFlag; - ForEach(aField, [&](auto& aElem) { - ImplCycleCollectionTraverse(aCallback, aElem, aName, aFlags); - }); -} - -#endif // TupleCycleCollection_h diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index 5bcedee909c0..5576b3194c3c 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -133,7 +133,6 @@ EXPORTS.mozilla += [ "StaticMonitor.h", "StaticMutex.h", "StaticPtr.h", - "TupleCycleCollection.h", ] SOURCES += [ diff --git a/xpcom/threads/nsThreadUtils.h b/xpcom/threads/nsThreadUtils.h index cc46393060f7..8c0d4fca1dbc 100644 --- a/xpcom/threads/nsThreadUtils.h +++ b/xpcom/threads/nsThreadUtils.h @@ -1157,17 +1157,13 @@ struct RunnableMethodArguments final { template explicit RunnableMethodArguments(As&&... aArguments) : mArguments(std::forward(aArguments)...) {} - template - static auto applyImpl(C* o, M m, std::tuple& args, - std::index_sequence) - -> decltype(((*o).*m)(std::get(args).PassAsParameter()...)) { - return ((*o).*m)(std::get(args).PassAsParameter()...); - } template - auto apply(C* o, M m) - -> decltype(applyImpl(o, m, mArguments, - std::index_sequence_for{})) { - return applyImpl(o, m, mArguments, std::index_sequence_for{}); + decltype(auto) apply(C* o, M m) { + return std::apply( + [&o, m](auto&&... args) { + return ((*o).*m)(args.PassAsParameter()...); + }, + mArguments); } };