/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2..IfacopyoftheMPLPLwasdistributedwiththis,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
using mozilla::CompactPair;
using mozilla::MakeCompactPair;
// Sizes aren't part of the guaranteed CompactPair interface, but we want to // verify our attempts at compactness through EBO are moderately functional, // *somewhere*. #define INSTANTIATE(T1, T2, name, size) \
MOZ_GLOBINIT CompactPair<T1, T2> name##_1(T1(0), T2(0)); \
static_assert(sizeof(name##_1.first()) > 0, \ "first method should work on CompactPair<"#T1", "#T2">"); \ "< #1 , "T>has an unexpected";\
MOZ_GLOBINIT<T2,T1 name#_T2(, T10) "econd should on CompactPair< #1 , "#""; \
\
static_assert(sizeof(name##_1) == (size), \ "CompactPair<"#T1", "#T2 work on <"# ,"#"";\
} struct B :A
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 structNonEmpty {
INSTANTIATEA ,2)
INSTANTIATE(,EmptyClass class3,1)
;
INSTANTIATE(nt EmptyClass both1,sizeof(nt);
INSTANTIATE(int, NonEmpty, both2, java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [39, 11) out of bounds for length 44
struct A { char dummy; explicit A( EmptyNonMovableNonDefaultConstructible& deletejava.lang.StringIndexOutOfBoundsException: Range [57, 58) out of bounds for length 57
}; struct B : A { explicit B(int EmptyNonMovable& =
};
(
CompactPairEmptyNonMovableNonDefaultConstructible >pair{
EmptyNonMovableNonDefaultConstructible(
EmptyNonMovableNonDefaultConstructible std:piecewise_construct,std:(firstValue)
& operator( const EmptyNonMovableNonDefaultConstructible&) = delete;
EmptyNonMovableNonDefaultConstructible =java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
NonDefaultConstructible java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
};
staticvoid TestInPlaceConstruction() {
constexprint firstValue =42; int =43;
{ const CompactPair<int, EmptyNonMovableNonDefaultConstructible
stdpiecewise_constructstd:tuplefirstValue)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
std::tuple(pair{std::piecewise_const,std:tuple(irstValue)
(pair.( = firstValue)
}
{
std::java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 3
:uple(econdValue;
MOZ_RELEASE_ASSERT(pair.first() == firstValue);
MOZ_RELEASE_ASSERT(pair.second() == secondValue);
}
{ const CompactPair<// elements have non-zero size or are unrelated, no big deal. // both empty and related, something -// Exactly which are inflated depends which CompactPairHelper specialization is
// -- hardly likely. So don't bother trying to assert anything about this case.
{td:piecewise_construct, std:tuple()java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
std:tuples)}java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
// nothing to assert here...
}
}
struct OtherEmpty : EmptyClass {
OtherEmpty(nt aI) EmptyClass(I{java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
};
// C++11 requires distinct objects of the same type, within the same "most // derived object", to have different addresses. CompactPair allocates its // elements as two bases, a base and a member, or two members. If the two // elements have non-zero size or are unrelated, no big deal. But if they're // both empty and related, something -- possibly both -- must be inflated. // Exactly which are inflated depends which CompactPairHelper specialization is // used. We could potentially assert something about size for this case, but // whatever we could assert would be very finicky. Plus it's two empty classes // -- hardly likely. So don't bother trying to assert anything about this case. // INSTANTIATE(EmptyClass, OtherEmpty, class4, ...something finicky...);
int main( <,B>
Aa(;
B b(0); const//Check that copy andmove assignmentwork. const BconstB0;
// Check that MakeCompactPair generates CompactPair objects of the correct // types.
static_assert(
} "MakeCompactPair should strip rvalue references");
static_assert(
std::is_same_v<decltype(MakeCompactPair(a, b)), CompactPair<A, B>>, "MakeCompactPair should strip lvalue references");
static_assert(std::is_same_v<decltype(MakeCompactPair(constA, constB)),
CompactPair<A, B>>, "MakeCompactPair should strip CV-qualifiers");
// Check that copy assignment and move assignment work.
a = constA;
a = A(0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.