18 #include <initializer_list>
20 #include <type_traits>
22 #include "gtest/gtest.h"
23 #include "absl/base/config.h"
24 #include "absl/meta/type_traits.h"
25 #include "absl/utility/utility.h"
28 "These tests assume that the small object storage is at least "
29 "the size of a pointer.");
36 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
37 #define ABSL_INTERNAL_NOEXCEPT_SPEC(noex) noexcept(noex)
39 #define ABSL_INTERNAL_NOEXCEPT_SPEC(noex)
61 template <
class Qualifiers,
class This>
62 struct QualifiersForThisImpl {
68 template <
class Qualifiers,
class This>
69 struct QualifiersForThisImpl<Qualifiers&, This>
70 : QualifiersForThisImpl<Qualifiers, This> {};
72 template <
class Qualifiers,
class This>
73 struct QualifiersForThisImpl<Qualifiers&&, This> {
79 template <
class Qualifiers,
class This>
80 using QualifiersForThis =
81 typename QualifiersForThisImpl<Qualifiers, This>::type;
85 template <
class T,
class Fun>
86 struct GiveQualifiersToFunImpl;
88 template <
class T,
class R,
class...
P>
89 struct GiveQualifiersToFunImpl<
T, R(
P...)> {
95 struct GiveQualifiersToFunImpl<
T&, R(
P...)> {
101 struct GiveQualifiersToFunImpl<
T&&, R(
P...)> {
107 #if defined(__cpp_noexcept_function_type)
109 template <
class T,
class R,
class...
P>
110 struct GiveQualifiersToFunImpl<
T, R(
P...) noexcept> {
112 R(
P...)
const noexcept, R(
P...) noexcept>;
116 struct GiveQualifiersToFunImpl<
T&, R(
P...) noexcept> {
123 struct GiveQualifiersToFunImpl<
T&&, R(
P...) noexcept> {
126 R(
P...) && noexcept>;
129 #endif // defined(__cpp_noexcept_function_type)
131 template <
class T,
class Fun>
136 enum class ObjSize { small,
large };
141 template <ObjSize Size>
142 struct TypeErasedPadding;
145 struct TypeErasedPadding<ObjSize::small> {};
148 struct TypeErasedPadding<ObjSize::
large> {
162 Int(
Int&&
v) noexcept =
default;
164 operator int() && noexcept {
return value; }
166 int MemberFunctionAdd(
int const&
b,
int c) noexcept {
173 enum class Movable { no, yes, nothrow, trivial };
175 enum class NothrowCall { no, yes };
177 enum class Destructible { nothrow, trivial };
179 enum class ObjAlign : std::size_t {
186 template <Movable Movability, Destructible Destructibility,
class Qual,
187 NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
190 #define ABSL_INTERNALS_ADD(qual) \
191 template <NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment> \
192 struct alignas(static_cast<std::size_t>(Alignment)) \
193 add<Movable::trivial, Destructible::trivial, _ qual, CallExceptionSpec, \
194 Size, Alignment> : TypeErasedPadding<Size> { \
195 explicit add(int state_init) : state(state_init) {} \
196 explicit add(std::initializer_list<int> state_init, int tail) \
197 : state(std::accumulate(std::begin(state_init), std::end(state_init), \
200 add(add&& other) = default; \
201 Int operator()(int a, int b, int c) qual \
202 ABSL_INTERNAL_NOEXCEPT_SPEC(CallExceptionSpec == NothrowCall::yes) { \
203 return state + a + b + c; \
208 template <NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment> \
209 struct alignas(static_cast<std::size_t>(Alignment)) \
210 add<Movable::trivial, Destructible::nothrow, _ qual, CallExceptionSpec, \
211 Size, Alignment> : TypeErasedPadding<Size> { \
212 explicit add(int state_init) : state(state_init) {} \
213 explicit add(std::initializer_list<int> state_init, int tail) \
214 : state(std::accumulate(std::begin(state_init), std::end(state_init), \
218 add(add&& other) = default; \
219 Int operator()(int a, int b, int c) qual \
220 ABSL_INTERNAL_NOEXCEPT_SPEC(CallExceptionSpec == NothrowCall::yes) { \
221 return state + a + b + c; \
229 #define ABSL_INTERNALS_NOARG
231 #undef ABSL_INTERNALS_NOARG
239 #undef ABSL_INTERNALS_ADD
241 template <Destructible Destructibility,
class Qual,
242 NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
243 struct add<Movable::no, Destructibility, Qual, CallExceptionSpec, Size,
244 Alignment> :
private add<Movable::trivial, Destructibility, Qual,
245 CallExceptionSpec, Size, Alignment> {
246 using Base =
add<Movable::trivial, Destructibility, Qual, CallExceptionSpec,
249 explicit add(
int state_init) : Base(state_init) {}
251 explicit add(std::initializer_list<int> state_init,
int tail)
252 : Base(state_init, tail) {}
256 using Base::operator();
260 template <Destructible Destructibility,
class Qual,
261 NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
262 struct add<Movable::yes, Destructibility, Qual, CallExceptionSpec, Size,
263 Alignment> :
private add<Movable::trivial, Destructibility, Qual,
264 CallExceptionSpec, Size, Alignment> {
265 using Base =
add<Movable::trivial, Destructibility, Qual, CallExceptionSpec,
268 explicit add(
int state_init) : Base(state_init) {}
270 explicit add(std::initializer_list<int> state_init,
int tail)
271 : Base(state_init, tail) {}
273 add(
add&& other) noexcept(
false) : Base(other.
state) {}
275 using Base::operator();
279 template <Destructible Destructibility,
class Qual,
280 NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
281 struct add<Movable::nothrow, Destructibility, Qual, CallExceptionSpec, Size,
282 Alignment> :
private add<Movable::trivial, Destructibility, Qual,
283 CallExceptionSpec, Size, Alignment> {
284 using Base =
add<Movable::trivial, Destructibility, Qual, CallExceptionSpec,
287 explicit add(
int state_init) : Base(state_init) {}
289 explicit add(std::initializer_list<int> state_init,
int tail)
290 : Base(state_init, tail) {}
292 add(
add&& other) noexcept : Base(other.state) {}
294 using Base::operator();
299 Int add_function(
Int&&
a,
int b,
int c) noexcept {
return a.value +
b +
c; }
301 Int mult_function(
Int&&
a,
int b,
int c) noexcept {
return a.value *
b *
c; }
303 Int square_function(
Int const&&
a) noexcept {
return a.value *
a.value; }
310 template <Movable Movability, Destructible Destructibility,
class Qual,
311 NothrowCall CallExceptionSpec, ObjSize Size, ObjAlign Alignment>
313 static constexpr Movable kMovability = Movability;
314 static constexpr Destructible kDestructibility = Destructibility;
315 using Qualifiers = Qual;
316 static constexpr NothrowCall kCallExceptionSpec = CallExceptionSpec;
317 static constexpr
bool kIsNoexcept = kCallExceptionSpec == NothrowCall::yes;
318 static constexpr
bool kIsRvalueQualified =
320 static constexpr ObjSize
kSize = Size;
321 static constexpr ObjAlign
kAlignment = Alignment;
324 using UnqualifiedUnaryFunType =
int(
Int const&&)
326 using UnaryFunType = GiveQualifiersToFun<Qualifiers, UnqualifiedUnaryFunType>;
327 using MemObjPtrType =
int(
Int::*);
328 using UnaryAnyInvType = AnyInvocable<UnaryFunType>;
329 using UnaryThisParamType = QualifiersForThis<Qualifiers, UnaryAnyInvType>;
332 static UnaryThisParamType ToUnaryThisParam(
T&& fun) {
333 return static_cast<UnaryThisParamType
>(fun);
344 using ResultType =
Int;
345 using AnyInvocableFunTypeNotNoexcept =
Int(
Int,
const int&,
int);
346 using UnqualifiedFunType =
347 typename std::conditional<kIsNoexcept,
Int(
Int,
const int&,
int) noexcept,
349 using FunType = GiveQualifiersToFun<Qualifiers, UnqualifiedFunType>;
350 using MemFunPtrType =
351 typename std::conditional<kIsNoexcept,
354 using AnyInvType = AnyInvocable<FunType>;
355 using AddType =
add<kMovability, kDestructibility, Qualifiers,
357 using ThisParamType = QualifiersForThis<Qualifiers, AnyInvType>;
360 static ThisParamType ToThisParam(
T&& fun) {
361 return static_cast<ThisParamType
>(fun);
365 using UnqualifiedVoidFunType =
366 typename std::conditional<kIsNoexcept,
367 void(
Int,
const int&,
int) noexcept,
369 using VoidFunType = GiveQualifiersToFun<Qualifiers, UnqualifiedVoidFunType>;
370 using VoidAnyInvType = AnyInvocable<VoidFunType>;
371 using VoidThisParamType = QualifiersForThis<Qualifiers, VoidAnyInvType>;
374 static VoidThisParamType ToVoidThisParam(
T&& fun) {
375 return static_cast<VoidThisParamType
>(fun);
378 using CompatibleAnyInvocableFunType =
380 GiveQualifiersToFun<const _&&, UnqualifiedFunType>,
381 GiveQualifiersToFun<const _&, UnqualifiedFunType>>;
383 using CompatibleAnyInvType = AnyInvocable<CompatibleAnyInvocableFunType>;
385 using IncompatibleInvocable =
387 GiveQualifiersToFun<_&, UnqualifiedFunType>(
_::*),
388 GiveQualifiersToFun<_&&, UnqualifiedFunType>(
_::*)>;
395 template <
class MemberPtrType>
396 struct MemberTypeOfImpl;
398 template <
class Class,
class T>
399 struct MemberTypeOfImpl<
T(Class::*)> {
403 template <
class MemberPtrType>
406 template <
class T,
class =
void>
408 static constexpr
bool kIsNothrow =
false;
412 struct IsMemberSwappableImpl<
413 T,
absl::
void_t<decltype(std::declval<T&>().swap(std::declval<T&>()))>>
415 static constexpr
bool kIsNothrow =
416 noexcept(std::declval<T&>().
swap(std::declval<T&>()));
420 using IsMemberSwappable = IsMemberSwappableImpl<T>;
423 using IsNothrowMemberSwappable =
424 std::integral_constant<bool, IsMemberSwappableImpl<T>::kIsNothrow>;
432 using AnyInvType =
typename TypeParam::AnyInvType;
442 using AnyInvType =
typename TypeParam::AnyInvType;
444 AnyInvType fun =
nullptr;
452 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullFunctionPtr) {
453 using AnyInvType =
typename TypeParam::AnyInvType;
454 using UnqualifiedFunType =
typename TypeParam::UnqualifiedFunType;
456 UnqualifiedFunType*
const null_fun_ptr =
nullptr;
457 AnyInvType fun = null_fun_ptr;
462 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullMemberFunctionPtr) {
463 using AnyInvType =
typename TypeParam::AnyInvType;
464 using MemFunPtrType =
typename TypeParam::MemFunPtrType;
466 const MemFunPtrType null_mem_fun_ptr =
nullptr;
467 AnyInvType fun = null_mem_fun_ptr;
472 TYPED_TEST_P(AnyInvTestBasic, ConstructionNullMemberObjectPtr) {
473 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
474 using MemObjPtrType =
typename TypeParam::MemObjPtrType;
476 const MemObjPtrType null_mem_obj_ptr =
nullptr;
477 UnaryAnyInvType fun = null_mem_obj_ptr;
482 TYPED_TEST_P(AnyInvTestBasic, ConstructionMemberFunctionPtr) {
483 using AnyInvType =
typename TypeParam::AnyInvType;
485 AnyInvType fun = &Int::MemberFunctionAdd;
491 TYPED_TEST_P(AnyInvTestBasic, ConstructionMemberObjectPtr) {
492 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
497 EXPECT_EQ(13, TypeParam::ToUnaryThisParam(fun)(13));
500 TYPED_TEST_P(AnyInvTestBasic, ConstructionFunctionReferenceDecay) {
501 using AnyInvType =
typename TypeParam::AnyInvType;
503 AnyInvType fun = add_function;
509 TYPED_TEST_P(AnyInvTestBasic, ConstructionCompatibleAnyInvocableEmpty) {
510 using AnyInvType =
typename TypeParam::AnyInvType;
511 using CompatibleAnyInvType =
typename TypeParam::CompatibleAnyInvType;
513 CompatibleAnyInvType other;
523 TYPED_TEST_P(AnyInvTestBasic, ConstructionCompatibleAnyInvocableNonempty) {
524 using AnyInvType =
typename TypeParam::AnyInvType;
525 using CompatibleAnyInvType =
typename TypeParam::CompatibleAnyInvType;
527 CompatibleAnyInvType other = &add_function;
539 using AnyInvType =
typename TypeParam::AnyInvType;
554 AnyInvType fun = &add_function;
562 using AnyInvType =
typename TypeParam::AnyInvType;
564 using FunType =
typename TypeParam::FunType;
565 using AnyInvCallType = MemberTypeOf<decltype(&AnyInvType::operator())>;
571 AnyInvType fun = &add_function;
577 using AnyInvType =
typename TypeParam::AnyInvType;
578 using AddType =
typename TypeParam::AddType;
580 AnyInvType fun(absl::in_place_type<AddType>, 5);
586 TYPED_TEST_P(AnyInvTestBasic, InPlaceConstructionInitializerList) {
587 using AnyInvType =
typename TypeParam::AnyInvType;
588 using AddType =
typename TypeParam::AddType;
590 AnyInvType fun(absl::in_place_type<AddType>, {1, 2, 3, 4}, 5);
596 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullFunPtrConstruction) {
597 using AnyInvType =
typename TypeParam::AnyInvType;
598 using UnqualifiedFunType =
typename TypeParam::UnqualifiedFunType;
600 AnyInvType fun(absl::in_place_type<UnqualifiedFunType*>,
nullptr);
606 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullFunPtrConstructionValueInit) {
607 using AnyInvType =
typename TypeParam::AnyInvType;
608 using UnqualifiedFunType =
typename TypeParam::UnqualifiedFunType;
610 AnyInvType fun(absl::in_place_type<UnqualifiedFunType*>);
616 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemFunPtrConstruction) {
617 using AnyInvType =
typename TypeParam::AnyInvType;
618 using MemFunPtrType =
typename TypeParam::MemFunPtrType;
620 AnyInvType fun(absl::in_place_type<MemFunPtrType>,
nullptr);
626 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemFunPtrConstructionValueInit) {
627 using AnyInvType =
typename TypeParam::AnyInvType;
628 using MemFunPtrType =
typename TypeParam::MemFunPtrType;
630 AnyInvType fun(absl::in_place_type<MemFunPtrType>);
636 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemObjPtrConstruction) {
637 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
638 using MemObjPtrType =
typename TypeParam::MemObjPtrType;
640 UnaryAnyInvType fun(absl::in_place_type<MemObjPtrType>,
nullptr);
646 TYPED_TEST_P(AnyInvTestBasic, InPlaceNullMemObjPtrConstructionValueInit) {
647 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
648 using MemObjPtrType =
typename TypeParam::MemObjPtrType;
650 UnaryAnyInvType fun(absl::in_place_type<MemObjPtrType>);
656 TYPED_TEST_P(AnyInvTestBasic, InPlaceVoidCovarianceConstruction) {
657 using VoidAnyInvType =
typename TypeParam::VoidAnyInvType;
658 using AddType =
typename TypeParam::AddType;
660 VoidAnyInvType fun(absl::in_place_type<AddType>, 5);
665 TYPED_TEST_P(AnyInvTestBasic, MoveConstructionFromEmpty) {
666 using AnyInvType =
typename TypeParam::AnyInvType;
668 AnyInvType source_fun;
676 TYPED_TEST_P(AnyInvTestBasic, MoveConstructionFromNonEmpty) {
677 using AnyInvType =
typename TypeParam::AnyInvType;
678 using AddType =
typename TypeParam::AddType;
680 AnyInvType source_fun(absl::in_place_type<AddType>, 5);
689 TYPED_TEST_P(AnyInvTestBasic, ComparisonWithNullptrEmpty) {
690 using AnyInvType =
typename TypeParam::AnyInvType;
701 TYPED_TEST_P(AnyInvTestBasic, ComparisonWithNullptrNonempty) {
702 using AnyInvType =
typename TypeParam::AnyInvType;
703 using AddType =
typename TypeParam::AddType;
705 AnyInvType fun(absl::in_place_type<AddType>, 5);
715 using AnyInvType =
typename TypeParam::AnyInvType;
716 using ExpectedResultType =
typename TypeParam::ResultType;
719 ExpectedResultType>::
value));
727 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignEmptyEmptyLhsRhs) {
728 using AnyInvType =
typename TypeParam::AnyInvType;
730 AnyInvType source_fun;
738 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignEmptyLhsNonemptyRhs) {
739 using AnyInvType =
typename TypeParam::AnyInvType;
740 using AddType =
typename TypeParam::AddType;
742 AnyInvType source_fun(absl::in_place_type<AddType>, 5);
751 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignNonemptyEmptyLhsRhs) {
752 using AnyInvType =
typename TypeParam::AnyInvType;
753 using AddType =
typename TypeParam::AddType;
755 AnyInvType source_fun;
756 AnyInvType fun(absl::in_place_type<AddType>, 5);
763 TYPED_TEST_P(AnyInvTestCombinatoric, MoveAssignNonemptyLhsNonemptyRhs) {
764 using AnyInvType =
typename TypeParam::AnyInvType;
765 using AddType =
typename TypeParam::AddType;
767 AnyInvType source_fun(absl::in_place_type<AddType>, 5);
768 AnyInvType fun(absl::in_place_type<AddType>, 20);
776 TYPED_TEST_P(AnyInvTestCombinatoric, SelfMoveAssignEmpty) {
777 using AnyInvType =
typename TypeParam::AnyInvType;
779 AnyInvType source_fun;
785 TYPED_TEST_P(AnyInvTestCombinatoric, SelfMoveAssignNonempty) {
786 using AnyInvType =
typename TypeParam::AnyInvType;
787 using AddType =
typename TypeParam::AddType;
789 AnyInvType source_fun(absl::in_place_type<AddType>, 5);
795 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullptrEmptyLhs) {
796 using AnyInvType =
typename TypeParam::AnyInvType;
804 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullFunctionPtrEmptyLhs) {
805 using AnyInvType =
typename TypeParam::AnyInvType;
806 using UnqualifiedFunType =
typename TypeParam::UnqualifiedFunType;
808 UnqualifiedFunType*
const null_fun_ptr =
nullptr;
815 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberFunctionPtrEmptyLhs) {
816 using AnyInvType =
typename TypeParam::AnyInvType;
817 using MemFunPtrType =
typename TypeParam::MemFunPtrType;
819 const MemFunPtrType null_mem_fun_ptr =
nullptr;
821 fun = null_mem_fun_ptr;
826 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberObjectPtrEmptyLhs) {
827 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
828 using MemObjPtrType =
typename TypeParam::MemObjPtrType;
830 const MemObjPtrType null_mem_obj_ptr =
nullptr;
832 fun = null_mem_obj_ptr;
837 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberFunctionPtrEmptyLhs) {
838 using AnyInvType =
typename TypeParam::AnyInvType;
841 fun = &Int::MemberFunctionAdd;
847 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberObjectPtrEmptyLhs) {
848 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
854 EXPECT_EQ(13, TypeParam::ToUnaryThisParam(fun)(13));
857 TYPED_TEST_P(AnyInvTestCombinatoric, AssignFunctionReferenceDecayEmptyLhs) {
858 using AnyInvType =
typename TypeParam::AnyInvType;
868 AssignCompatibleAnyInvocableEmptyLhsEmptyRhs) {
869 using AnyInvType =
typename TypeParam::AnyInvType;
870 using CompatibleAnyInvType =
typename TypeParam::CompatibleAnyInvType;
872 CompatibleAnyInvType other;
884 AssignCompatibleAnyInvocableEmptyLhsNonemptyRhs) {
885 using AnyInvType =
typename TypeParam::AnyInvType;
886 using CompatibleAnyInvType =
typename TypeParam::CompatibleAnyInvType;
888 CompatibleAnyInvType other = &add_function;
898 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullptrNonemptyLhs) {
899 using AnyInvType =
typename TypeParam::AnyInvType;
901 AnyInvType fun = &mult_function;
907 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullFunctionPtrNonemptyLhs) {
908 using AnyInvType =
typename TypeParam::AnyInvType;
909 using UnqualifiedFunType =
typename TypeParam::UnqualifiedFunType;
911 UnqualifiedFunType*
const null_fun_ptr =
nullptr;
912 AnyInvType fun = &mult_function;
918 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberFunctionPtrNonemptyLhs) {
919 using AnyInvType =
typename TypeParam::AnyInvType;
920 using MemFunPtrType =
typename TypeParam::MemFunPtrType;
922 const MemFunPtrType null_mem_fun_ptr =
nullptr;
923 AnyInvType fun = &mult_function;
924 fun = null_mem_fun_ptr;
929 TYPED_TEST_P(AnyInvTestCombinatoric, AssignNullMemberObjectPtrNonemptyLhs) {
930 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
931 using MemObjPtrType =
typename TypeParam::MemObjPtrType;
933 const MemObjPtrType null_mem_obj_ptr =
nullptr;
934 UnaryAnyInvType fun = &square_function;
935 fun = null_mem_obj_ptr;
940 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberFunctionPtrNonemptyLhs) {
941 using AnyInvType =
typename TypeParam::AnyInvType;
943 AnyInvType fun = &mult_function;
944 fun = &Int::MemberFunctionAdd;
950 TYPED_TEST_P(AnyInvTestCombinatoric, AssignMemberObjectPtrNonemptyLhs) {
951 using UnaryAnyInvType =
typename TypeParam::UnaryAnyInvType;
953 UnaryAnyInvType fun = &square_function;
957 EXPECT_EQ(13, TypeParam::ToUnaryThisParam(fun)(13));
960 TYPED_TEST_P(AnyInvTestCombinatoric, AssignFunctionReferenceDecayNonemptyLhs) {
961 using AnyInvType =
typename TypeParam::AnyInvType;
963 AnyInvType fun = &mult_function;
971 AssignCompatibleAnyInvocableNonemptyLhsEmptyRhs) {
972 using AnyInvType =
typename TypeParam::AnyInvType;
973 using CompatibleAnyInvType =
typename TypeParam::CompatibleAnyInvType;
975 CompatibleAnyInvType other;
976 AnyInvType fun = &mult_function;
987 AssignCompatibleAnyInvocableNonemptyLhsNonemptyRhs) {
988 using AnyInvType =
typename TypeParam::AnyInvType;
989 using CompatibleAnyInvType =
typename TypeParam::CompatibleAnyInvType;
991 CompatibleAnyInvType other = &add_function;
992 AnyInvType fun = &mult_function;
1001 TYPED_TEST_P(AnyInvTestCombinatoric, SwapEmptyLhsEmptyRhs) {
1002 using AnyInvType =
typename TypeParam::AnyInvType;
1033 TYPED_TEST_P(AnyInvTestCombinatoric, SwapEmptyLhsNonemptyRhs) {
1034 using AnyInvType =
typename TypeParam::AnyInvType;
1035 using AddType =
typename TypeParam::AddType;
1040 AnyInvType other(absl::in_place_type<AddType>, 5);
1057 AnyInvType other(absl::in_place_type<AddType>, 5);
1070 TYPED_TEST_P(AnyInvTestCombinatoric, SwapNonemptyLhsEmptyRhs) {
1071 using AnyInvType =
typename TypeParam::AnyInvType;
1072 using AddType =
typename TypeParam::AddType;
1076 AnyInvType fun(absl::in_place_type<AddType>, 5);
1093 AnyInvType fun(absl::in_place_type<AddType>, 5);
1107 TYPED_TEST_P(AnyInvTestCombinatoric, SwapNonemptyLhsNonemptyRhs) {
1108 using AnyInvType =
typename TypeParam::AnyInvType;
1109 using AddType =
typename TypeParam::AddType;
1113 AnyInvType fun(absl::in_place_type<AddType>, 5);
1114 AnyInvType other(absl::in_place_type<AddType>, 6);
1131 AnyInvType fun(absl::in_place_type<AddType>, 5);
1132 AnyInvType other(absl::in_place_type<AddType>, 6);
1151 TYPED_TEST_P(AnyInvTestMovable, ConversionConstructionUserDefinedType) {
1152 using AnyInvType =
typename TypeParam::AnyInvType;
1153 using AddType =
typename TypeParam::AddType;
1155 AnyInvType fun(AddType(5));
1164 TYPED_TEST_P(AnyInvTestMovable, ConversionConstructionVoidCovariance) {
1165 using VoidAnyInvType =
typename TypeParam::VoidAnyInvType;
1166 using AddType =
typename TypeParam::AddType;
1168 VoidAnyInvType fun(AddType(5));
1173 TYPED_TEST_P(AnyInvTestMovable, ConversionAssignUserDefinedTypeEmptyLhs) {
1174 using AnyInvType =
typename TypeParam::AnyInvType;
1175 using AddType =
typename TypeParam::AddType;
1187 TYPED_TEST_P(AnyInvTestMovable, ConversionAssignUserDefinedTypeNonemptyLhs) {
1188 using AnyInvType =
typename TypeParam::AnyInvType;
1189 using AddType =
typename TypeParam::AddType;
1191 AnyInvType fun = &add_function;
1201 TYPED_TEST_P(AnyInvTestMovable, ConversionAssignVoidCovariance) {
1202 using VoidAnyInvType =
typename TypeParam::VoidAnyInvType;
1203 using AddType =
typename TypeParam::AddType;
1216 TYPED_TEST_P(AnyInvTestNoexceptFalse, ConversionConstructionConstraints) {
1217 using AnyInvType =
typename TypeParam::AnyInvType;
1221 typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::
value));
1223 std::is_constructible<AnyInvType,
1224 typename TypeParam::IncompatibleInvocable>::
value));
1227 TYPED_TEST_P(AnyInvTestNoexceptFalse, ConversionAssignConstraints) {
1228 using AnyInvType =
typename TypeParam::AnyInvType;
1232 typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::
value));
1234 (std::is_assignable<AnyInvType&,
1235 typename TypeParam::IncompatibleInvocable>::
value));
1243 TYPED_TEST_P(AnyInvTestNoexceptTrue, ConversionConstructionConstraints) {
1244 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1245 GTEST_SKIP() <<
"Noexcept was not part of the type system before C++17.";
1247 using AnyInvType =
typename TypeParam::AnyInvType;
1253 typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::
value));
1256 std::is_constructible<AnyInvType,
1257 typename TypeParam::IncompatibleInvocable>::
value));
1261 TYPED_TEST_P(AnyInvTestNoexceptTrue, ConversionAssignConstraints) {
1262 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1263 GTEST_SKIP() <<
"Noexcept was not part of the type system before C++17.";
1265 using AnyInvType =
typename TypeParam::AnyInvType;
1271 typename TypeParam::AnyInvocableFunTypeNotNoexcept*>::
value));
1274 (std::is_assignable<AnyInvType&,
1275 typename TypeParam::IncompatibleInvocable>::
value));
1284 TYPED_TEST_P(AnyInvTestNonRvalue, ConversionConstructionReferenceWrapper) {
1285 using AnyInvType =
typename TypeParam::AnyInvType;
1286 using AddType =
typename TypeParam::AddType;
1299 TYPED_TEST_P(AnyInvTestNonRvalue, NonMoveableResultType) {
1300 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1301 GTEST_SKIP() <<
"Copy/move elision was not standard before C++17";
1307 explicit Result(
const int x_in) :
x(x_in) {}
1316 const auto return_17 = []() noexcept {
return Result(17); };
1321 using UnqualifiedFun =
1325 GiveQualifiersToFun<typename TypeParam::Qualifiers, UnqualifiedFun>;
1327 AnyInvocable<Fun> any_inv(return_17);
1332 TYPED_TEST_P(AnyInvTestNonRvalue, ConversionAssignReferenceWrapperEmptyLhs) {
1333 using AnyInvType =
typename TypeParam::AnyInvType;
1334 using AddType =
typename TypeParam::AddType;
1341 (std::is_nothrow_assignable<AnyInvType&,
1342 std::reference_wrapper<AddType>>::
value));
1351 TYPED_TEST_P(AnyInvTestNonRvalue, ConversionAssignReferenceWrapperNonemptyLhs) {
1352 using AnyInvType =
typename TypeParam::AnyInvType;
1353 using AddType =
typename TypeParam::AddType;
1356 AnyInvType fun = &mult_function;
1360 (std::is_nothrow_assignable<AnyInvType&,
1361 std::reference_wrapper<AddType>>::
value));
1375 TYPED_TEST_P(AnyInvTestRvalue, ConversionConstructionReferenceWrapper) {
1376 using AnyInvType =
typename TypeParam::AnyInvType;
1377 using AddType =
typename TypeParam::AddType;
1380 std::is_convertible<std::reference_wrapper<AddType>, AnyInvType>::
value));
1383 TYPED_TEST_P(AnyInvTestRvalue, NonMoveableResultType) {
1384 #if ABSL_INTERNAL_CPLUSPLUS_LANG < 201703L
1385 GTEST_SKIP() <<
"Copy/move elision was not standard before C++17";
1391 explicit Result(
const int x_in) :
x(x_in) {}
1400 const auto return_17 = []() noexcept {
return Result(17); };
1405 using UnqualifiedFun =
1409 GiveQualifiersToFun<typename TypeParam::Qualifiers, UnqualifiedFun>;
1411 EXPECT_EQ(17, AnyInvocable<Fun>(return_17)().
x);
1415 TYPED_TEST_P(AnyInvTestRvalue, ConversionAssignReferenceWrapper) {
1416 using AnyInvType =
typename TypeParam::AnyInvType;
1417 using AddType =
typename TypeParam::AddType;
1420 std::is_assignable<AnyInvType&, std::reference_wrapper<AddType>>::
value));
1430 template <Movable Mov, Destructible Dest, NothrowCall CallExceptionSpec,
1431 ObjSize Size, ObjAlign
Align>
1433 TestParams<Mov, Dest, _, CallExceptionSpec, Size, Align>,
1434 TestParams<Mov, Dest, const _, CallExceptionSpec, Size, Align>,
1435 TestParams<Mov, Dest, _&, CallExceptionSpec, Size, Align>,
1436 TestParams<Mov, Dest, const _&, CallExceptionSpec, Size, Align>>;
1440 template <Movable Mov, Destructible Dest, NothrowCall CallExceptionSpec,
1441 ObjSize Size, ObjAlign
Align>
1443 TestParams<Mov, Dest, _&&, CallExceptionSpec, Size, Align>,
1444 TestParams<Mov, Dest, const _&&, CallExceptionSpec, Size, Align>
1448 using TestParameterListNonRvalueQualifiersNothrowCall =
1449 NonRvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1450 NothrowCall::yes, ObjSize::small,
1452 using TestParameterListRvalueQualifiersNothrowCall =
1453 RvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1454 NothrowCall::yes, ObjSize::small,
1458 using TestParameterListNonRvalueQualifiersCallMayThrow =
1459 NonRvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1460 NothrowCall::no, ObjSize::small,
1462 using TestParameterListRvalueQualifiersCallMayThrow =
1463 RvalueQualifiedTestParams<Movable::trivial, Destructible::trivial,
1464 NothrowCall::no, ObjSize::small,
1470 TestParams<Movable::trivial, Destructible::trivial,
_, NothrowCall::no,
1472 TestParams<Movable::nothrow, Destructible::trivial,
_, NothrowCall::no,
1474 TestParams<Movable::yes, Destructible::trivial,
_, NothrowCall::no,
1475 ObjSize::small, ObjAlign::normal>,
1476 TestParams<Movable::yes, Destructible::trivial,
_, NothrowCall::no,
1480 TestParams<Movable::trivial, Destructible::nothrow,
_, NothrowCall::no,
1482 TestParams<Movable::nothrow, Destructible::nothrow,
_, NothrowCall::no,
1484 TestParams<Movable::yes, Destructible::nothrow,
_, NothrowCall::no,
1485 ObjSize::small, ObjAlign::normal>,
1486 TestParams<Movable::yes, Destructible::nothrow,
_, NothrowCall::no,
1491 #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L
1494 TestParams<Movable::trivial, Destructible::trivial,
_, NothrowCall::no,
1496 TestParams<Movable::nothrow, Destructible::trivial,
_, NothrowCall::no,
1498 TestParams<Movable::trivial, Destructible::nothrow,
_, NothrowCall::no,
1500 TestParams<Movable::nothrow, Destructible::nothrow,
_, NothrowCall::no,
1506 TestParams<Movable::no, Destructible::trivial,
_, NothrowCall::no,
1507 ObjSize::small, ObjAlign::normal>,
1508 TestParams<Movable::no, Destructible::trivial,
_, NothrowCall::no,
1511 TestParams<Movable::no, Destructible::nothrow,
_, NothrowCall::no,
1512 ObjSize::small, ObjAlign::normal>,
1513 TestParams<Movable::no, Destructible::nothrow,
_, NothrowCall::no,
1520 TestParams<Movable::trivial, Destructible::trivial,
_, NothrowCall::no,
1521 ObjSize::small, ObjAlign::normal>,
1522 TestParams<Movable::nothrow, Destructible::trivial,
_, NothrowCall::no,
1523 ObjSize::small, ObjAlign::normal>,
1526 TestParams<Movable::trivial, Destructible::trivial,
_, NothrowCall::no,
1527 ObjSize::small, ObjAlign::normal>,
1528 TestParams<Movable::nothrow, Destructible::trivial,
_, NothrowCall::no,
1529 ObjSize::small, ObjAlign::normal>
1534 AnyInvTestBasic, DefaultConstruction, ConstructionNullptr,
1535 ConstructionNullFunctionPtr, ConstructionNullMemberFunctionPtr,
1536 ConstructionNullMemberObjectPtr, ConstructionMemberFunctionPtr,
1537 ConstructionMemberObjectPtr, ConstructionFunctionReferenceDecay,
1538 ConstructionCompatibleAnyInvocableEmpty,
1539 ConstructionCompatibleAnyInvocableNonempty, InPlaceConstruction,
1540 ConversionToBool, Invocation, InPlaceConstructionInitializerList,
1541 InPlaceNullFunPtrConstruction, InPlaceNullFunPtrConstructionValueInit,
1542 InPlaceNullMemFunPtrConstruction, InPlaceNullMemFunPtrConstructionValueInit,
1543 InPlaceNullMemObjPtrConstruction, InPlaceNullMemObjPtrConstructionValueInit,
1544 InPlaceVoidCovarianceConstruction, MoveConstructionFromEmpty,
1545 MoveConstructionFromNonEmpty, ComparisonWithNullptrEmpty,
1546 ComparisonWithNullptrNonempty, ResultType);
1549 NonRvalueCallMayThrow, AnyInvTestBasic,
1550 TestParameterListNonRvalueQualifiersCallMayThrow);
1552 TestParameterListRvalueQualifiersCallMayThrow);
1555 TestParameterListRemoteMovable);
1557 TestParameterListRemoteNonMovable);
1562 TestParameterListNonRvalueQualifiersNothrowCall);
1564 TestParameterListRvalueQualifiersNothrowCall);
1568 AnyInvTestCombinatoric, MoveAssignEmptyEmptyLhsRhs,
1569 MoveAssignEmptyLhsNonemptyRhs, MoveAssignNonemptyEmptyLhsRhs,
1570 MoveAssignNonemptyLhsNonemptyRhs, SelfMoveAssignEmpty,
1571 SelfMoveAssignNonempty, AssignNullptrEmptyLhs,
1572 AssignNullFunctionPtrEmptyLhs, AssignNullMemberFunctionPtrEmptyLhs,
1573 AssignNullMemberObjectPtrEmptyLhs, AssignMemberFunctionPtrEmptyLhs,
1574 AssignMemberObjectPtrEmptyLhs, AssignFunctionReferenceDecayEmptyLhs,
1575 AssignCompatibleAnyInvocableEmptyLhsEmptyRhs,
1576 AssignCompatibleAnyInvocableEmptyLhsNonemptyRhs, AssignNullptrNonemptyLhs,
1577 AssignNullFunctionPtrNonemptyLhs, AssignNullMemberFunctionPtrNonemptyLhs,
1578 AssignNullMemberObjectPtrNonemptyLhs, AssignMemberFunctionPtrNonemptyLhs,
1579 AssignMemberObjectPtrNonemptyLhs, AssignFunctionReferenceDecayNonemptyLhs,
1580 AssignCompatibleAnyInvocableNonemptyLhsEmptyRhs,
1581 AssignCompatibleAnyInvocableNonemptyLhsNonemptyRhs, SwapEmptyLhsEmptyRhs,
1582 SwapEmptyLhsNonemptyRhs, SwapNonemptyLhsEmptyRhs,
1583 SwapNonemptyLhsNonemptyRhs);
1586 NonRvalueCallMayThrow, AnyInvTestCombinatoric,
1587 TestParameterListNonRvalueQualifiersCallMayThrow);
1589 TestParameterListRvalueQualifiersCallMayThrow);
1592 TestParameterListRemoteMovable);
1594 TestParameterListRemoteNonMovable);
1597 TestParameterListLocal);
1600 TestParameterListNonRvalueQualifiersNothrowCall);
1602 TestParameterListRvalueQualifiersNothrowCall);
1605 ConversionConstructionUserDefinedType,
1606 ConversionConstructionVoidCovariance,
1607 ConversionAssignUserDefinedTypeEmptyLhs,
1608 ConversionAssignUserDefinedTypeNonemptyLhs,
1609 ConversionAssignVoidCovariance);
1612 NonRvalueCallMayThrow, AnyInvTestMovable,
1613 TestParameterListNonRvalueQualifiersCallMayThrow);
1615 TestParameterListRvalueQualifiersCallMayThrow);
1618 TestParameterListRemoteMovable);
1621 TestParameterListLocal);
1624 TestParameterListNonRvalueQualifiersNothrowCall);
1626 TestParameterListRvalueQualifiersNothrowCall);
1629 ConversionConstructionConstraints,
1630 ConversionAssignConstraints);
1633 NonRvalueCallMayThrow, AnyInvTestNoexceptFalse,
1634 TestParameterListNonRvalueQualifiersCallMayThrow);
1636 TestParameterListRvalueQualifiersCallMayThrow);
1639 TestParameterListRemoteMovable);
1641 TestParameterListRemoteNonMovable);
1644 TestParameterListLocal);
1647 ConversionConstructionConstraints,
1648 ConversionAssignConstraints);
1651 TestParameterListNonRvalueQualifiersNothrowCall);
1653 TestParameterListRvalueQualifiersNothrowCall);
1656 ConversionConstructionReferenceWrapper,
1657 NonMoveableResultType,
1658 ConversionAssignReferenceWrapperEmptyLhs,
1659 ConversionAssignReferenceWrapperNonemptyLhs);
1662 NonRvalueCallMayThrow, AnyInvTestNonRvalue,
1663 TestParameterListNonRvalueQualifiersCallMayThrow);
1666 TestParameterListRemoteMovable);
1668 TestParameterListRemoteNonMovable);
1671 TestParameterListLocal);
1674 TestParameterListNonRvalueQualifiersNothrowCall);
1677 ConversionConstructionReferenceWrapper,
1678 NonMoveableResultType,
1679 ConversionAssignReferenceWrapper);
1682 TestParameterListRvalueQualifiersCallMayThrow);
1685 TestParameterListRvalueQualifiersNothrowCall);
1694 #undef ABSL_INTERNAL_NOEXCEPT_SPEC