std::vector<RefCount*> refCounts_;
std::vector<folly::Function<void()>> decrefs_;
};
+
+template <typename T, typename RefCount>
+inline bool operator==(
+ const ReadMostlyMainPtr<T, RefCount>& ptr,
+ std::nullptr_t) {
+ return ptr.get() == nullptr;
+}
+
+template <typename T, typename RefCount>
+inline bool operator==(
+ std::nullptr_t,
+ const ReadMostlyMainPtr<T, RefCount>& ptr) {
+ return ptr.get() == nullptr;
+}
+
+template <typename T, typename RefCount>
+inline bool operator==(
+ const ReadMostlySharedPtr<T, RefCount>& ptr,
+ std::nullptr_t) {
+ return ptr.get() == nullptr;
+}
+
+template <typename T, typename RefCount>
+inline bool operator==(
+ std::nullptr_t,
+ const ReadMostlySharedPtr<T, RefCount>& ptr) {
+ return ptr.get() == nullptr;
+}
+
+template <typename T, typename RefCount>
+inline bool operator!=(
+ const ReadMostlyMainPtr<T, RefCount>& ptr,
+ std::nullptr_t) {
+ return !(ptr == nullptr);
+}
+
+template <typename T, typename RefCount>
+inline bool operator!=(
+ std::nullptr_t,
+ const ReadMostlyMainPtr<T, RefCount>& ptr) {
+ return !(ptr == nullptr);
+}
+
+template <typename T, typename RefCount>
+inline bool operator!=(
+ const ReadMostlySharedPtr<T, RefCount>& ptr,
+ std::nullptr_t) {
+ return !(ptr == nullptr);
+}
+
+template <typename T, typename RefCount>
+inline bool operator!=(
+ std::nullptr_t,
+ const ReadMostlySharedPtr<T, RefCount>& ptr) {
+ return !(ptr == nullptr);
+}
}
EXPECT_EQ(1, useGlobalCalls);
}
+
+TEST_F(ReadMostlySharedPtrTest, nullptr) {
+ {
+ ReadMostlyMainPtr<int, TestRefCount> nptr;
+ EXPECT_TRUE(nptr == nullptr);
+ EXPECT_TRUE(nullptr == nptr);
+ EXPECT_EQ(nptr, nullptr);
+ EXPECT_EQ(nullptr, nptr);
+ EXPECT_FALSE(nptr);
+ EXPECT_TRUE(!nptr);
+
+ ReadMostlyMainPtr<int, TestRefCount> ptr(std::make_shared<int>(42));
+ EXPECT_FALSE(ptr == nullptr);
+ EXPECT_FALSE(nullptr == ptr);
+ EXPECT_NE(ptr, nullptr);
+ EXPECT_NE(nullptr, ptr);
+ EXPECT_FALSE(!ptr);
+ EXPECT_TRUE(ptr);
+ }
+ {
+ ReadMostlySharedPtr<int, TestRefCount> nptr;
+ EXPECT_TRUE(nptr == nullptr);
+ EXPECT_TRUE(nullptr == nptr);
+ EXPECT_EQ(nptr, nullptr);
+ EXPECT_EQ(nullptr, nptr);
+ EXPECT_FALSE(nptr);
+ EXPECT_TRUE(!nptr);
+
+ ReadMostlyMainPtr<int, TestRefCount> ptr(std::make_shared<int>(42));
+ EXPECT_FALSE(ptr == nullptr);
+ EXPECT_FALSE(nullptr == ptr);
+ EXPECT_NE(ptr, nullptr);
+ EXPECT_NE(nullptr, ptr);
+ EXPECT_FALSE(!ptr);
+ EXPECT_TRUE(ptr);
+ }
+}