23 #include <initializer_list> 28 #include <type_traits> 29 #include <unordered_map> 32 #include <boost/optional.hpp> 34 using std::shared_ptr;
35 using std::unique_ptr;
42 std::ostream& operator<<(std::ostream& os, const Optional<V>&
v) {
44 os <<
"Optional(" <<
v.value() <<
')';
58 static_assert(
sizeof(Optional<char>) == 2,
"");
59 static_assert(
sizeof(Optional<int>) == 8,
"");
60 static_assert(
sizeof(Optional<NoDefault>) == 4,
"");
61 static_assert(
sizeof(Optional<char>) ==
sizeof(boost::optional<char>),
"");
62 static_assert(
sizeof(Optional<short>) ==
sizeof(boost::optional<short>),
"");
63 static_assert(
sizeof(Optional<int>) ==
sizeof(boost::optional<int>),
"");
64 static_assert(
sizeof(Optional<double>) ==
sizeof(boost::optional<double>),
"");
77 auto& values1 = opt.
emplace(3, 4);
79 auto& values2 = opt.
emplace(2, 5);
85 auto& values1 = opt.
emplace({3, 4, 5});
87 auto& values2 = opt.
emplace({4, 5, 6});
100 maybeString =
"hello";
164 bool operator==(
const MoveTester& o1,
const MoveTester& o2) {
165 return o1.s_ == o2.s_;
181 const auto& optc = opt;
186 EXPECT_EQ(
"world", optc.value_or(
"world"));
198 std::unique_ptr<int> dflt(
new int(42));
234 using A = std::pair<int, double>;
241 using A = std::pair<int, double>;
260 opt = std::make_unique<int>(6);
263 opt = std::make_unique<int>(7);
306 moved.emplace(
new int(6));
314 std::vector<Optional<int>> vect{
321 std::vector<Optional<int>> expected{
328 std::sort(vect.begin(), vect.end());
410 boost::optional<int> boi(3);
424 boost::optional<bool> bob(
false);
544 if (mbool && mshort && mstr && mint) {
545 if (*mbool && *mshort && *mstr && *mint) {
577 class ConstructibleWithArgsOnly {
579 explicit ConstructibleWithArgsOnly(
int,
double) {}
581 ConstructibleWithArgsOnly() =
delete;
582 ConstructibleWithArgsOnly(
const ConstructibleWithArgsOnly&) =
delete;
583 ConstructibleWithArgsOnly(ConstructibleWithArgsOnly&&) =
delete;
584 ConstructibleWithArgsOnly& operator=(
const ConstructibleWithArgsOnly&) =
586 ConstructibleWithArgsOnly& operator=(ConstructibleWithArgsOnly&&) =
delete;
589 class ConstructibleWithInitializerListAndArgsOnly {
591 ConstructibleWithInitializerListAndArgsOnly(std::initializer_list<int>,
int) {
594 ConstructibleWithInitializerListAndArgsOnly() =
delete;
595 ConstructibleWithInitializerListAndArgsOnly(
596 const ConstructibleWithInitializerListAndArgsOnly&) =
delete;
597 ConstructibleWithInitializerListAndArgsOnly(
598 ConstructibleWithInitializerListAndArgsOnly&&) =
delete;
599 ConstructibleWithInitializerListAndArgsOnly& operator=(
600 const ConstructibleWithInitializerListAndArgsOnly&) =
delete;
601 ConstructibleWithInitializerListAndArgsOnly& operator=(
602 ConstructibleWithInitializerListAndArgsOnly&&) =
delete;
634 unique_ptr<int> pInt(
new int(3));
642 auto&& optional = make_optional<ConstructibleWithArgsOnly>(
int{},
double{});
643 std::ignore = optional;
646 using Type = ConstructibleWithInitializerListAndArgsOnly;
647 auto&& optional = make_optional<Type>({
int{}},
double{});
648 std::ignore = optional;
653 using Type = ConstructibleWithInitializerListAndArgsOnly;
655 std::ignore = optional;
660 auto optional = make_optional<int>(1);
661 std::ignore = optional;
665 std::ignore = optional;
671 a =
static_cast<decltype(a)&
>(
a);
675 b =
static_cast<decltype(b)&&
>(
b);
676 ASSERT_TRUE(b.hasValue() && b.value() == 23333333);
681 class ContainsOptional {
683 ContainsOptional() {}
684 explicit ContainsOptional(
int x) :
opt_(x) {}
685 bool hasValue()
const {
692 ContainsOptional(
const ContainsOptional& other) =
default;
693 ContainsOptional& operator=(
const ContainsOptional& other) =
default;
694 ContainsOptional(ContainsOptional&& other) =
default;
695 ContainsOptional& operator=(ContainsOptional&& other) =
default;
710 ContainsOptional source(5), target;
717 ContainsOptional source(5), target;
725 ContainsOptional opt_uninit, target(10);
762 std::hash<Optional<int>>()(
none);
763 std::hash<Optional<int>>()(3);
768 struct WithConstMember {
769 WithConstMember(
int val) :
x(val) {}
802 auto op = make_optional<int>(10);
806 op = make_optional<int>(20);
std::atomic< int64_t > sum(0)
#define EXPECT_THROW(statement, expected_exception)
ExpectingDeleter(int expected_)
#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))))
constexpr Optional< _t< std::decay< T > > > make_optional(T &&v)
void operator()(const int *ptr)
constexpr auto empty(C const &c) -> decltype(c.empty())
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
internal::PointeeMatcher< InnerMatcher > Pointee(const InnerMatcher &inner_matcher)
Value & emplace(Args &&...args)
FOLLY_CPP14_CONSTEXPR Value value_or(U &&dflt) const &
#define EXPECT_TRUE(condition)
const Value * get_pointer(const Expected< Value, Error > &ex) noexcept
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
#define EXPECT_THAT(value, matcher)
bool operator==(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
FOLLY_CPP14_CONSTEXPR const Value & value() const &
#define EXPECT_FALSE(condition)
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
#define ASSERT_TRUE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)