summaryrefslogtreecommitdiff
path: root/src/mongo/util
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2021-04-08 01:34:45 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-21 14:20:13 +0000
commitedfe720bfe35c186f7f3f31dbb541ccb1f449d0a (patch)
tree14d4f019f17fc9277582869d2f3e70efcef371df /src/mongo/util
parentde3c2bf165ff5a1851be4e0be5e1ad6263aa15ba (diff)
downloadmongo-edfe720bfe35c186f7f3f31dbb541ccb1f449d0a.tar.gz
SERVER-55887 remove unowned_ptr
Diffstat (limited to 'src/mongo/util')
-rw-r--r--src/mongo/util/SConscript1
-rw-r--r--src/mongo/util/unowned_ptr.h110
-rw-r--r--src/mongo/util/unowned_ptr_test.cpp158
3 files changed, 0 insertions, 269 deletions
diff --git a/src/mongo/util/SConscript b/src/mongo/util/SConscript
index ee75e3724f5..dc61bbab177 100644
--- a/src/mongo/util/SConscript
+++ b/src/mongo/util/SConscript
@@ -669,7 +669,6 @@ icuEnv.CppUnitTest(
'tick_source_test.cpp',
'time_support_test.cpp',
'unique_function_test.cpp',
- 'unowned_ptr_test.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/util/unowned_ptr.h b/src/mongo/util/unowned_ptr.h
deleted file mode 100644
index b9baee9536a..00000000000
--- a/src/mongo/util/unowned_ptr.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <memory>
-#include <type_traits>
-
-namespace mongo {
-
-/**
- * A "smart" pointer that explicitly indicates a lack of ownership.
- * It will implicitly convert from any compatible pointer type.
- *
- * Note that like other pointer types const applies to the pointer not the pointee:
- * - const unowned_ptr<T> => T* const
- * - unowned_ptr<const T> => const T*
- */
-template <typename T>
-struct unowned_ptr {
- unowned_ptr() = default;
-
- //
- // Implicit conversions from compatible pointer types
- //
-
- // Removes conversions from overload resolution if the underlying pointer types aren't
- // convertible. This makes this class behave more like a bare pointer.
- template <typename U>
- using IfConvertibleFrom = typename std::enable_if<std::is_convertible<U*, T*>::value>::type;
-
- // Needed for NULL since it won't match U* constructor.
- unowned_ptr(T* p) : _p(p) {}
-
- template <typename U, typename = IfConvertibleFrom<U>>
- unowned_ptr(U* p) : _p(p) {}
-
- template <typename U, typename = IfConvertibleFrom<U>>
- unowned_ptr(const unowned_ptr<U>& p) : _p(p) {}
-
- template <typename U, typename Deleter, typename = IfConvertibleFrom<U>>
- unowned_ptr(const std::unique_ptr<U, Deleter>& p) : _p(p.get()) {}
-
- template <typename U, typename = IfConvertibleFrom<U>>
- unowned_ptr(const std::shared_ptr<U>& p) : _p(p.get()) {}
-
- //
- // Modifiers
- //
-
- void reset(unowned_ptr p = nullptr) {
- _p = p.get();
- }
- void swap(unowned_ptr& other) {
- std::swap(_p, other._p);
- }
-
- //
- // Accessors
- //
-
- T* get() const {
- return _p;
- }
- operator T*() const {
- return _p;
- }
-
- //
- // Pointer syntax
- //
-
- T* operator->() const {
- return _p;
- }
- T& operator*() const {
- return *_p;
- }
-
-private:
- T* _p = nullptr;
-};
-
-} // namespace mongo
diff --git a/src/mongo/util/unowned_ptr_test.cpp b/src/mongo/util/unowned_ptr_test.cpp
deleted file mode 100644
index b6acea486f6..00000000000
--- a/src/mongo/util/unowned_ptr_test.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * Copyright (C) 2018-present MongoDB, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the Server Side Public License, version 1,
- * as published by MongoDB, Inc.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Server Side Public License for more details.
- *
- * You should have received a copy of the Server Side Public License
- * along with this program. If not, see
- * <http://www.mongodb.com/licensing/server-side-public-license>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the Server Side Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/util/unowned_ptr.h"
-
-#include "mongo/unittest/unittest.h"
-
-namespace mongo {
-static int* const aNullPtr = nullptr;
-
-TEST(UnownedPtr, Construction) {
- // non-const
- std::unique_ptr<int> p1(new int(1));
- std::shared_ptr<int> p2(new int(2));
- std::unique_ptr<int> p3(new int(3));
- std::shared_ptr<int> p4(new int(4));
-
- ASSERT_EQUALS(aNullPtr, unowned_ptr<int>());
- ASSERT_EQUALS(aNullPtr, unowned_ptr<int>({}));
- ASSERT_EQUALS(aNullPtr, unowned_ptr<int>(nullptr));
- ASSERT_EQUALS(aNullPtr, unowned_ptr<int>(nullptr));
- ASSERT_EQUALS(p1.get(), unowned_ptr<int>(p1.get()));
- ASSERT_EQUALS(p1.get(), unowned_ptr<int>(p1));
- ASSERT_EQUALS(p2.get(), unowned_ptr<int>(p2));
- ASSERT_EQUALS(p2.get(), unowned_ptr<int>(unowned_ptr<int>(p2)));
-
- // const
- std::unique_ptr<const int> cp1(new int(11));
- std::shared_ptr<const int> cp2(new int(12));
-
- ASSERT_EQUALS(aNullPtr, unowned_ptr<const int>());
- ASSERT_EQUALS(aNullPtr, unowned_ptr<const int>({}));
- ASSERT_EQUALS(aNullPtr, unowned_ptr<const int>(nullptr));
- ASSERT_EQUALS(aNullPtr, unowned_ptr<const int>(nullptr));
- ASSERT_EQUALS(p1.get(), unowned_ptr<const int>(p1.get()));
- ASSERT_EQUALS(cp1.get(), unowned_ptr<const int>(cp1.get()));
- ASSERT_EQUALS(p1.get(), unowned_ptr<const int>(p1));
- ASSERT_EQUALS(p2.get(), unowned_ptr<const int>(p2));
- ASSERT_EQUALS(p3.get(), unowned_ptr<const int>(p3));
- ASSERT_EQUALS(p4.get(), unowned_ptr<const int>(p4));
- ASSERT_EQUALS(cp1.get(), unowned_ptr<const int>(cp1));
- ASSERT_EQUALS(cp2.get(), unowned_ptr<const int>(cp2));
- ASSERT_EQUALS(p2.get(), unowned_ptr<const int>(unowned_ptr<const int>(p2)));
- ASSERT_EQUALS(p2.get(), unowned_ptr<const int>(unowned_ptr<int>(p2)));
-
- // These shouldn't compile since they'd drop constness:
- //(void)unowned_ptr<int>(cp1);
- //(void)unowned_ptr<int>(cp2);
- //(void)unowned_ptr<int>(unowned_ptr<const int>(p2));
-}
-
-TEST(UnownedPtr, Assignment) {
- // non-const
- std::unique_ptr<int> p1(new int(1));
- std::shared_ptr<int> p2(new int(2));
- std::unique_ptr<int> p3(new int(3));
- std::shared_ptr<int> p4(new int(4));
-
- ASSERT_EQUALS(aNullPtr, (unowned_ptr<int>() = {}));
- ASSERT_EQUALS(aNullPtr, (unowned_ptr<int>() = nullptr));
- ASSERT_EQUALS(aNullPtr, (unowned_ptr<int>() = nullptr));
- ASSERT_EQUALS(p1.get(), (unowned_ptr<int>() = p1.get()));
- ASSERT_EQUALS(p1.get(), (unowned_ptr<int>() = p1));
- ASSERT_EQUALS(p2.get(), (unowned_ptr<int>() = p2));
- ASSERT_EQUALS(p2.get(), (unowned_ptr<int>() = unowned_ptr<int>(p2)));
-
- // const
- std::unique_ptr<const int> cp1(new int(11));
- std::shared_ptr<const int> cp2(new int(12));
-
- ASSERT_EQUALS(aNullPtr, (unowned_ptr<const int>() = {}));
- ASSERT_EQUALS(aNullPtr, (unowned_ptr<const int>() = nullptr));
- ASSERT_EQUALS(aNullPtr, (unowned_ptr<const int>() = nullptr));
- ASSERT_EQUALS(p1.get(), (unowned_ptr<const int>() = p1.get()));
- ASSERT_EQUALS(cp1.get(), (unowned_ptr<const int>() = cp1.get()));
- ASSERT_EQUALS(p1.get(), (unowned_ptr<const int>() = p1));
- ASSERT_EQUALS(p2.get(), (unowned_ptr<const int>() = p2));
- ASSERT_EQUALS(p3.get(), (unowned_ptr<const int>() = p3));
- ASSERT_EQUALS(p4.get(), (unowned_ptr<const int>() = p4));
- ASSERT_EQUALS(cp1.get(), (unowned_ptr<const int>() = cp1));
- ASSERT_EQUALS(cp2.get(), (unowned_ptr<const int>() = cp2));
- ASSERT_EQUALS(p2.get(), (unowned_ptr<const int>() = unowned_ptr<const int>(p2)));
- ASSERT_EQUALS(p2.get(), (unowned_ptr<const int>() = unowned_ptr<int>(p2)));
-
- // These shouldn't compile since they'd drop constness:
- // unowned_ptr<int>() = cp1;
- // unowned_ptr<int>() = cp2;
- // unowned_ptr<int>() = unowned_ptr<const int>(p2);
-}
-
-TEST(UnownedPtr, ArgumentOverloading) {
- struct Base {
- } base;
- struct Derived : Base {
- } derived;
- struct Other {
- } other;
-
- struct {
- StringData operator()(unowned_ptr<Base>) {
- return "base";
- }
- StringData operator()(unowned_ptr<Other>) {
- return "other";
- }
- // Unfortunately unowned_ptr<Derived> would be ambiguous. You can only overload on
- // unrelated types.
- } overloadedFunction;
-
- ASSERT_EQ(overloadedFunction(&base), "base");
- ASSERT_EQ(overloadedFunction(&derived), "base");
- ASSERT_EQ(overloadedFunction(&other), "other");
-}
-
-TEST(UnownedPtr, Boolishness) {
- ASSERT_FALSE(unowned_ptr<const char>());
- ASSERT_TRUE(unowned_ptr<const char>(""));
-}
-
-TEST(UnownedPtr, Equality) {
- int i = 0;
- int j = 0;
-
- ASSERT_EQ(unowned_ptr<int>(), unowned_ptr<int>()); // NULL
- ASSERT_EQ(unowned_ptr<int>(&i), unowned_ptr<int>(&i)); // non-NULL
-
- ASSERT_NE(unowned_ptr<int>(), unowned_ptr<int>(&i)); // NULL != non-NULL
- ASSERT_NE(unowned_ptr<int>(&i), unowned_ptr<int>(&j)); // two distinct non-NULLs
-}
-} // namespace mongo