28 void func(
int a,
int b,
double c) {
35 void func(
int a,
int b,
double c) {
39 double retVal(
int a,
double b) {
44 Wat(Wat
const&) =
delete;
59 int operator()()
const {
66 CopyCount(CopyCount
const&) {
67 std::cout <<
"copy count copy ctor\n";
71 void anotherFunc(CopyCount
const&) {}
73 std::function<void(int, int, double)> makeFunc() {
78 GuardObjBase(GuardObjBase&&)
noexcept {}
80 GuardObjBase(GuardObjBase
const&) =
delete;
81 GuardObjBase& operator=(GuardObjBase
const&) =
delete;
83 typedef GuardObjBase
const& Guard;
85 template <
class F,
class Tuple>
86 struct GuardObj : GuardObjBase {
87 explicit GuardObj(F&&
f, Tuple&& args)
88 : f_(
std::forward<F>(
f)), args_(
std::forward<Tuple>(args)) {}
98 GuardObj(
const GuardObj&) =
delete;
99 GuardObj& operator=(
const GuardObj&) =
delete;
106 template <
class F,
class...
Args>
110 return GuardObj<typename std::decay<F>::type, std::tuple<
Args...>>(
111 std::forward<F>(
f), std::tuple<Args...>(std::forward<Args>(args)...));
117 Mover(
const Mover&) =
delete;
118 Mover& operator=(
const Mover&) =
delete;
121 void move_only_func(Mover&&) {}
134 std::unique_ptr<Wat> wat(
new Wat);
144 auto test2 =
guard(anotherFunc, cpy);
145 auto test3 =
guard(anotherFunc, std::cref(cpy));
151 static_cast<int (Overloaded::*)(
int)
>(&Overloaded::func),
156 static_cast<bool (Overloaded::*)(
bool)
>(&Overloaded::func),
164 move_only_func, std::forward_as_tuple(std::forward<Mover>(Mover())));
173 [](
int a,
int b,
double c)
mutable { func(a, b, c); }, argsTuple);
176 TEST(ApplyTuple, ConstOverloads) {
177 struct ConstOverloaded {
182 int operator()()
const {
187 ConstOverloaded covl;
201 TEST(ApplyTuple, RefOverloads) {
202 struct RefOverloaded {
207 int operator()()
const& {
210 int operator()() && {
241 TEST(ApplyTuple, MemberFunction) {
254 TEST(ApplyTuple, MemberFunctionWithRefWrapper) {
262 TEST(ApplyTuple, MemberFunctionWithConstPointer) {
273 TEST(ApplyTuple, MemberFunctionWithSharedPtr) {
283 TEST(ApplyTuple, MemberFunctionWithUniquePtr) {
299 auto add = [](
int x,
int y) {
return x +
y; };
304 TEST(ApplyTuple, MultipleTuples) {
305 auto add = [](
int x,
int y,
int z) {
return x * 100 + y * 10 +
z; };
345 TEST(ApplyTuple, UncurryCopyMove) {
346 std::string separator =
"================================\n";
349 return separator + a +
"\n" + b +
"\n" + separator;
352 auto expected = separator +
"hello\nworld\n" + separator;
354 auto formatRowCopy = formatRow;
356 auto formatRowMove =
std::move(formatRow);
366 })(std::pair<int, int>(6, 7)));
369 })(std::pair<int&&, int&&>(6, 7)));
372 })(std::pair<int&&, int&&>(6, 7)));
374 std::string long1 =
"a long string exceeding small string size";
393 TEST(ApplyTuple, UncurryStdFind) {
394 std::vector<std::pair<int, int>>
v{{1, 9}, {2, 8}, {3, 7}, {4, 6}, {5, 5}};
403 template <
typename...
Args>
404 explicit S(
Args&&... args) : tuple_(std::forward<Args>(args)...) {}
406 std::tuple<int, double, std::string> tuple_;
411 S expected{42, 1.0,
"foobar"};
414 auto s1 = folly::make_from_tuple<S>(expected.tuple_);
418 S sCopy{expected.tuple_};
419 auto s2 = folly::make_from_tuple<S>(
std::move(sCopy.tuple_));
426 folly::make_from_tuple<S>(std::forward_as_tuple(42, 1.0,
std::move(str)));
431 TEST(MakeIndexSequenceFromTuple, Basic) {
434 using OneElementTuple = std::tuple<int>;
435 using TwoElementTuple = std::tuple<int>;
438 index_sequence_for_tuple<OneElementTuple>,
439 index_sequence<0>>::
value));
441 index_sequence_for_tuple<const OneElementTuple>,
442 index_sequence<0>>::
value));
445 index_sequence_for_tuple<TwoElementTuple>,
446 index_sequence<0>>::
value));
448 index_sequence_for_tuple<const TwoElementTuple>,
449 index_sequence<0>>::
value));
454 auto f = [](
auto) ->
int {
return {}; };
463 [](double) ->
double {
return {}; },
464 [](int, int) ->
int {
return {}; });
494 TEST(IsNothrowApplicable, Basic) {
503 [](
int)
noexcept {}, [](double) ->
double {
return {}; });
516 auto f = []() ->
int {
return {}; };
523 [](
int)
noexcept {}, [](double) ->
double {
return {}; });
534 TEST(IsNothrowApplicableR, Basic) {
543 is_nothrow_applicable_r<
double, decltype(
f), std::tuple<int>>{}));
547 [](
int)
noexcept {}, [](double) ->
double {
return {}; });
550 is_nothrow_applicable_r<
float, decltype(
f), std::tuple<double>>{}));
558 std::tuple<int, double>>::
value));
567 std::tuple<int&, double&>>::
value));
571 std::tuple<const int&, const double&>>::
value));
576 std::tuple<int&&, double&&>>::
value));
581 std::tuple<const int&, const double&>>::
value));
585 auto floating_point = 2.0;
586 auto ref_tuple = std::forward_as_tuple(integer,
std::move(floating_point));
590 std::tuple<int&, double&>>::
value));
594 std::tuple<int&, double&&>>::
value));
597 decltype(std::tuple_cat(
600 std::tuple<int&, double&, int&&, double&&>>::
value));
make_index_sequence< std::tuple_size< Tuple >::value > index_sequence_for_tuple
auto forward_tuple(Tuple &&tuple) noexcept-> decltype(detail::apply_tuple::adl::forward_tuple(std::declval< Tuple >(), std::declval< index_sequence_for_tuple< std::remove_reference_t< Tuple >>>()))
auto uncurry(F &&f) -> detail::apply_tuple::Uncurry< typename std::decay< F >::type >
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
constexpr T const & as_const(T &t) noexcept
internal::PairMatcher< FirstMatcher, SecondMatcher > Pair(FirstMatcher first_matcher, SecondMatcher second_matcher)
GuardImpl guard(ErrorHandler &&handler)
integer_sequence< std::size_t, Ints... > index_sequence
static map< string, int > m
static const char *const value
invoke_result_t< ApplyInvoke, F, Tuple > apply_result_t
#define EXPECT_TRUE(condition)
#define EXPECT_NE(val1, val2)
decltype(auto) overload(Cases &&...cases)
#define EXPECT_FALSE(condition)
constexpr T make_from_tuple(Tuple &&t)
decltype(auto) constexpr apply(F &&func, Tuple &&tuple)