19 #include <glog/logging.h> 25 using namespace folly;
31 explicit A(
int x) :
x_(x) {}
41 template <
bool Nothrow>
44 explicit HasCtors(
int)
noexcept(Nothrow) {}
45 HasCtors(HasCtors&&)
noexcept(Nothrow) {}
46 HasCtors& operator=(HasCtors&&)
noexcept(Nothrow) {}
47 HasCtors(HasCtors
const&)
noexcept(Nothrow) {}
48 HasCtors& operator=(HasCtors
const&)
noexcept(Nothrow) {}
51 class MoveConstructOnly {
53 MoveConstructOnly() =
default;
54 MoveConstructOnly(
const MoveConstructOnly&) =
delete;
55 MoveConstructOnly(MoveConstructOnly&&) =
default;
58 class MutableContainer {
60 mutable MoveConstructOnly
val;
85 TEST(
Try, assignmentWithThrowingCopyConstructor) {
87 struct ThrowingCopyConstructor {
93 [[noreturn]] ThrowingCopyConstructor(
94 const ThrowingCopyConstructor& other)
noexcept(
false)
99 ThrowingCopyConstructor& operator=(
const ThrowingCopyConstructor&) =
delete;
101 ~ThrowingCopyConstructor() {
130 TEST(
Try, assignmentWithThrowingMoveConstructor) {
132 struct ThrowingMoveConstructor {
138 [[noreturn]] ThrowingMoveConstructor(
139 ThrowingMoveConstructor&& other)
noexcept(
false)
144 ThrowingMoveConstructor& operator=(ThrowingMoveConstructor&&) =
delete;
146 ~ThrowingMoveConstructor() {
222 TEST(
Try, tryEmplaceWithThrowingConstructor) {
224 struct NonInheritingException {};
227 throw NonInheritingException{};
336 using F = HasCtors<false>;
337 using T = HasCtors<true>;
376 auto ptr = std::make_unique<int>(1);
389 static_cast<void>(
val);
394 static_cast<void>(
val);
401 using CL =
const int&;
402 using CR =
const int&&;
406 using ActualML = decltype(obj.value());
425 auto obj =
Try<int>{make_exception_wrapper<std::range_error>(
"oops")};
442 std::vector<Try<std::unique_ptr<int>>>
v;
447 auto func = []() {
return std::make_unique<int>(1); };
455 auto func = []() -> std::unique_ptr<int> {
456 throw std::runtime_error(
"Runtime");
460 EXPECT_TRUE(result.hasException<std::runtime_error>());
464 auto func = []() {
return; };
471 auto func = []() {
throw std::runtime_error(
"Runtime"); };
474 EXPECT_TRUE(result.hasException<std::runtime_error>());
485 using ActualML = decltype(obj.exception());
486 using ActualMR = decltype(
std::move(obj).exception());
487 using ActualCL = decltype(
as_const(obj).exception());
504 auto obj =
Try<int>(make_exception_wrapper<int>(-3));
505 EXPECT_EQ(-3, *obj.exception().get_exception<
int>());
513 using ActualML = decltype(obj.exception());
514 using ActualMR = decltype(
std::move(obj).exception());
515 using ActualCL = decltype(
as_const(obj).exception());
532 auto obj =
Try<void>(make_exception_wrapper<int>(-3));
533 EXPECT_EQ(-3, *obj.exception().get_exception<
int>());
540 template <
typename E>
543 std::rethrow_exception(eptr);
552 auto epexn = std::make_exception_ptr(std::range_error(
"oops"));
553 auto epnum = std::make_exception_ptr(17);
555 auto exn = CHECK_NOTNULL(get_exception<std::range_error>(epexn));
556 auto num = CHECK_NOTNULL(get_exception<int>(epnum));
560 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
561 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
562 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
568 EXPECT_EQ(exn,
t.tryGetExceptionObject<std::runtime_error>());
569 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
574 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
575 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
576 EXPECT_EQ(num,
t.tryGetExceptionObject<
int>());
581 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
582 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
583 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
589 EXPECT_EQ(exn,
t.tryGetExceptionObject<std::runtime_error>());
590 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
595 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
596 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
597 EXPECT_EQ(num,
t.tryGetExceptionObject<
int>());
602 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
603 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
604 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
610 EXPECT_EQ(exn,
t.tryGetExceptionObject<std::runtime_error>());
611 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
616 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
617 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
618 EXPECT_EQ(num,
t.tryGetExceptionObject<
int>());
623 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
624 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
625 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
631 EXPECT_EQ(exn,
t.tryGetExceptionObject<std::runtime_error>());
632 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<
int>());
637 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject());
638 EXPECT_EQ(
nullptr,
t.tryGetExceptionObject<std::runtime_error>());
639 EXPECT_EQ(num,
t.tryGetExceptionObject<
int>());
644 auto ew = make_exception_wrapper<std::range_error>(
"oops");
648 EXPECT_FALSE(
t.withException<std::runtime_error>([](
auto&) {}));
649 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
656 EXPECT_TRUE(
t.withException<std::runtime_error>([](
auto&) {}));
657 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
658 EXPECT_TRUE(
t.withException([](std::runtime_error&) {}));
664 EXPECT_FALSE(
t.withException<std::runtime_error>([](
auto&) {}));
665 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
672 EXPECT_TRUE(
t.withException<std::runtime_error>([](
auto&) {}));
673 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
674 EXPECT_TRUE(
t.withException([](std::runtime_error&) {}));
680 EXPECT_FALSE(
t.withException<std::runtime_error>([](
auto&) {}));
681 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
682 EXPECT_FALSE(
t.withException([](std::runtime_error
const&) {}));
683 EXPECT_FALSE(
t.withException([](std::logic_error
const&) {}));
688 EXPECT_TRUE(
t.withException<std::runtime_error>([](
auto&) {}));
689 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
690 EXPECT_TRUE(
t.withException([](std::runtime_error
const&) {}));
691 EXPECT_FALSE(
t.withException([](std::logic_error
const&) {}));
696 EXPECT_FALSE(
t.withException<std::runtime_error>([](
auto&) {}));
697 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
698 EXPECT_FALSE(
t.withException([](std::runtime_error
const&) {}));
699 EXPECT_FALSE(
t.withException([](std::logic_error
const&) {}));
704 EXPECT_TRUE(
t.withException<std::runtime_error>([](
auto&) {}));
705 EXPECT_FALSE(
t.withException<std::logic_error>([](
auto&) {}));
706 EXPECT_TRUE(
t.withException([](std::runtime_error
const&) {}));
707 EXPECT_FALSE(
t.withException([](std::logic_error
const&) {}));
726 using UPtr_t = std::unique_ptr<int>;
T * tryEmplace(Try< T > &t, Args &&...args) noexcept
bool hasException() const
#define EXPECT_THROW(statement, expected_exception)
T & emplace(Args &&...args) noexcept(std::is_nothrow_constructible< T, Args &&... >::value)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
in_place_tag in_place(in_place_tag={})
requires E e noexcept(noexcept(s.error(std::move(e))))
in_place_tag(&)(in_place_tag) in_place_t
T * tryEmplaceWith(Try< T > &t, Func &&func) noexcept
constexpr T const & as_const(T &t) noexcept
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
bool hasException() const
exception_wrapper & emplaceException(Args &&...args) noexcept(std::is_nothrow_constructible< exception_wrapper, Args &&... >::value)
std::exception * tryGetExceptionObject()
static const char *const value
#define EXPECT_TRUE(condition)
std::enable_if< !std::is_same< invoke_result_t< F >, void >::value, Try< invoke_result_t< F > > >::type makeTryWith(F &&f)
std::atomic< int > counter
#define EXPECT_NE(val1, val2)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
folly::detail::CompressionCounter * counter_
#define EXPECT_FALSE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
auto unwrapTryTuple(Tuple &&instance)
static E * get_exception(std::exception_ptr eptr)