28 int func_int_int_add_25(
int x) {
31 int func_int_int_add_111(
int x) {
34 float floatMult(
float a,
float b) {
38 template <
class T,
size_t S>
40 std::array<T, S>
data = {{0}};
44 T const& operator()(
size_t index)
const {
47 T operator()(
size_t index,
T const&
value) {
48 T oldvalue = data[index];
54 template <
typename Ret,
typename...
Args>
57 struct CallableButNotCopyable {
58 CallableButNotCopyable() {}
59 CallableButNotCopyable(CallableButNotCopyable
const&) =
delete;
60 CallableButNotCopyable(CallableButNotCopyable&&) =
delete;
61 CallableButNotCopyable& operator=(CallableButNotCopyable
const&) =
delete;
62 CallableButNotCopyable& operator=(CallableButNotCopyable&&) =
delete;
63 template <
class...
Args>
64 void operator()(
Args&&...)
const {}
72 !std::is_assignable<
Function<
void()>, CallableButNotCopyable>::
value,
75 !std::is_constructible<
Function<
void()>, CallableButNotCopyable&>::
value,
78 !std::is_constructible<
Function<
void()
const>, CallableButNotCopyable>::
82 !std::is_constructible<
Function<
void()
const>, CallableButNotCopyable&>::
87 !std::is_assignable<
Function<
void()>, CallableButNotCopyable>::
value,
90 !std::is_assignable<
Function<
void()>, CallableButNotCopyable&>::
value,
93 !std::is_assignable<
Function<
void()
const>, CallableButNotCopyable>::
value,
96 !std::is_assignable<
Function<
void()
const>, CallableButNotCopyable&>::
value,
159 std::is_nothrow_constructible<
164 !std::is_nothrow_constructible<
173 !std::is_nothrow_assignable<
179 !std::is_constructible<
Function<
int const&()>,
int (*)()>::
value,
183 !std::is_constructible<
Function<
int const&()
const>,
int (*)()>::
value,
186 #if FOLLY_HAVE_NOEXCEPT_FUNCTION_TYPE 201 Functor<int, 100> func;
203 sizeof(func) >
sizeof(
Function<
int(
size_t)>),
204 "sizeof(Function) is much larger than expected");
216 Functor<int, 10> func;
269 template <
bool UseSwapMethod>
341 auto unique_ptr_int = std::make_unique<int>(900);
350 [fooData](std::unique_ptr<int>& up)
mutable {
368 struct OverloadedFunctor {
370 int operator()(
int x) {
375 int operator()(
int x)
const {
380 int operator()(
int x,
int) {
385 int operator()(
int x,
int)
const {
390 int operator()(
int x,
char const*) {
395 int operator()(
int x, std::vector<int>
const&)
const {
399 OverloadedFunctor of;
408 EXPECT_EQ(100 + 3 * 17, variant3(17, 0));
411 EXPECT_EQ(100 + 4 * 18, variant4(18, 0));
414 EXPECT_EQ(100 + 5 * 19, variant5(19,
"foo"));
417 EXPECT_EQ(100 + 6 * 20, variant6(20, {}));
418 EXPECT_EQ(100 + 6 * 20, variant6(20, {1, 2, 3}));
421 EXPECT_EQ(100 + 6 * 21, variant6const(21, {}));
435 EXPECT_EQ(100 + 1 * 22, variant1_const(22));
439 EXPECT_EQ(100 + 2 * 23, variant2_nonconst(23));
443 EXPECT_EQ(100 + 3 * 24, variant3_const(24, 0));
447 EXPECT_EQ(100 + 4 * 25, variant4_nonconst(25, 0));
451 EXPECT_EQ(100 + 5 * 26, variant5_const(26,
"foo"));
455 EXPECT_EQ(100 + 6 * 27, variant6_const(27, {}));
459 EXPECT_THROW(variant6const(0, {}), std::bad_function_call);
460 EXPECT_EQ(100 + 6 * 28, variant6const_nonconst(28, {}));
489 EXPECT_EQ(2002, func_const_made_nonconst(2));
494 EXPECT_EQ(3003, func_mutable_made_const());
495 EXPECT_EQ(3004, func_mutable_made_const());
583 return data_->second;
586 return data_.use_count();
594 std::shared_ptr<std::pair<size_t, size_t>>
data_;
606 auto lambda1 = [cmt =
std::move(cmt)]() {
return cmt.moveCount(); };
610 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 3);
616 auto lambda2 = [cmt =
std::move(cmt)]() {
return cmt.moveCount(); };
620 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 3);
641 return c.moveCount();
647 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 2);
653 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 2);
658 return c.moveCount();
664 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 0);
669 return c.moveCount();
675 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 0);
680 return c.moveCount();
686 EXPECT_LE(cmt.moveCount() + cmt.copyCount(), 0);
697 template <
class...
Args>
699 return x + (*this)(args...);
717 va_start(args, count);
719 result += va_arg(args,
int);
746 template <
typename T>
749 Function<
void(
typename T::value_type
const&)
const>
const& func) {
750 for (
auto const& elem : range) {
756 std::vector<int>
const vec = {20, 30, 40, 2, 3, 4, 200, 300, 400};
763 for_each<std::vector<int>>(
vec, [&
sum](
int x) { sum +=
x; });
800 struct CDerived : CBase {};
841 struct CDerived : CBase {};
901 std::is_same<decltype(sf), std::function<
void()>>::
value,
902 "std::function has wrong type");
912 std::is_same<decltype(sf), std::function<
void()>>::
value,
913 "std::function has wrong type");
926 std::is_same<decltype(sf), std::function<
int()>>::
value,
927 "std::function has wrong type");
940 std::is_same<decltype(sf), std::function<
int()>>::
value,
941 "std::function has wrong type");
954 std::is_same<decltype(sf), std::function<
void(
int,
int)>>::
value,
955 "std::function has wrong type");
968 std::is_same<decltype(sf), std::function<
void(
int,
int)>>::
value,
969 "std::function has wrong type");
1040 return x * 100 +
y * 10 +
i;
1049 Functor<int, 100>
foo;
1061 auto functor = [&
x]() { ++
x; };
1096 f = [] {
return 43; };
1111 arg& operator=(arg&&) =
delete;
1121 EXPECT_FALSE(
bool(f)) <<
"self-assign is self-destruct";
1122 EXPECT_EQ(0, alive) <<
"self-asign is self-destruct";
1123 f = [] {
return 43; };
1124 EXPECT_EQ(0, alive) <<
"sanity check against double-destruction";
1130 deduceArgs(
Function<
void()>{[] {}});
1131 deduceArgs(
Function<
void(
int,
float)>{[](int, float) {}});
1132 deduceArgs(
Function<
int(
int,
float)>{[](
int i, float) {
return i; }});
1139 X& operator=(
X const&) =
default;
1145 Y& operator=(Y&&) =
default;
1146 Y& operator=(Y
const&) =
default;
1148 auto lx = [
x =
X()] {};
1149 auto ly = [
y = Y()] {};
#define EXPECT_LE(val1, val2)
std::atomic< int64_t > sum(0)
#define EXPECT_THROW(statement, expected_exception)
CopyMoveTracker & operator=(CopyMoveTracker &&o) noexcept
#define EXPECT_EQ(val1, val2)
int operator()(int x, Args...args) const
constexpr detail::Map< Move > move
void swap(Function &that) noexcept
int operator()(int count,...) const
CopyMoveTracker(ConstructorTag)
TEST(Function, InvokeFunctor)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
requires E e noexcept(noexcept(s.error(std::move(e))))
CopyMoveTracker(CopyMoveTracker &&o) noexcept
Gen range(Value begin, Value end)
CopyMoveTracker & operator=(CopyMoveTracker const &o) noexcept
static const char *const value
#define EXPECT_TRUE(condition)
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
std::shared_ptr< std::pair< size_t, size_t > > data_
Function< ReturnType(Args...) const > constCastFunction(Function< ReturnType(Args...)> &&) noexcept
int bind(NetworkSocket s, const sockaddr *name, socklen_t namelen)
#define EXPECT_NE(val1, val2)
CopyMoveTracker(CopyMoveTracker const &o) noexcept
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
void for_each(T const &range, Function< void(typename T::value_type const &) const > const &func)
#define EXPECT_FALSE(condition)
bool hasAllocatedMemory() const noexcept
static constexpr uint64_t data[1]