mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
remove unused class util::Ref and its unit test
This commit is contained in:
parent
8dbb87a393
commit
916ab0195d
5 changed files with 0 additions and 74 deletions
|
@ -243,7 +243,6 @@ BITCOIN_CORE_H = \
|
|||
util/moneystr.h \
|
||||
util/rbf.h \
|
||||
util/readwritefile.h \
|
||||
util/ref.h \
|
||||
util/settings.h \
|
||||
util/sock.h \
|
||||
util/spanparsing.h \
|
||||
|
|
|
@ -110,7 +110,6 @@ BITCOIN_TESTS =\
|
|||
test/prevector_tests.cpp \
|
||||
test/raii_event_tests.cpp \
|
||||
test/random_tests.cpp \
|
||||
test/ref_tests.cpp \
|
||||
test/reverselock_tests.cpp \
|
||||
test/rpc_tests.cpp \
|
||||
test/sanity_tests.cpp \
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/ref.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ref_tests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ref_test)
|
||||
{
|
||||
util::Ref ref;
|
||||
BOOST_CHECK(!ref.Has<int>());
|
||||
BOOST_CHECK_THROW(ref.Get<int>(), NonFatalCheckError);
|
||||
int value = 5;
|
||||
ref.Set(value);
|
||||
BOOST_CHECK(ref.Has<int>());
|
||||
BOOST_CHECK_EQUAL(ref.Get<int>(), 5);
|
||||
++ref.Get<int>();
|
||||
BOOST_CHECK_EQUAL(ref.Get<int>(), 6);
|
||||
BOOST_CHECK_EQUAL(value, 6);
|
||||
++value;
|
||||
BOOST_CHECK_EQUAL(value, 7);
|
||||
BOOST_CHECK_EQUAL(ref.Get<int>(), 7);
|
||||
BOOST_CHECK(!ref.Has<bool>());
|
||||
BOOST_CHECK_THROW(ref.Get<bool>(), NonFatalCheckError);
|
||||
ref.Clear();
|
||||
BOOST_CHECK(!ref.Has<int>());
|
||||
BOOST_CHECK_THROW(ref.Get<int>(), NonFatalCheckError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
|
@ -1,38 +0,0 @@
|
|||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_UTIL_REF_H
|
||||
#define BITCOIN_UTIL_REF_H
|
||||
|
||||
#include <util/check.h>
|
||||
|
||||
#include <typeindex>
|
||||
|
||||
namespace util {
|
||||
|
||||
/**
|
||||
* Type-safe dynamic reference.
|
||||
*
|
||||
* This implements a small subset of the functionality in C++17's std::any
|
||||
* class, and can be dropped when the project updates to C++17
|
||||
* (https://github.com/bitcoin/bitcoin/issues/16684)
|
||||
*/
|
||||
class Ref
|
||||
{
|
||||
public:
|
||||
Ref() = default;
|
||||
template<typename T> Ref(T& value) { Set(value); }
|
||||
template<typename T> T& Get() const { CHECK_NONFATAL(Has<T>()); return *static_cast<T*>(m_value); }
|
||||
template<typename T> void Set(T& value) { m_value = &value; m_type = std::type_index(typeid(T)); }
|
||||
template<typename T> bool Has() const { return m_value && m_type == std::type_index(typeid(T)); }
|
||||
void Clear() { m_value = nullptr; m_type = std::type_index(typeid(void)); }
|
||||
|
||||
private:
|
||||
void* m_value = nullptr;
|
||||
std::type_index m_type = std::type_index(typeid(void));
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
|
||||
#endif // BITCOIN_UTIL_REF_H
|
|
@ -57,7 +57,6 @@ IGNORED_WARNINGS=(
|
|||
"src/test/checkqueue_tests.cpp:.* Struct 'UniqueCheck' has a constructor with 1 argument that is not explicit."
|
||||
"src/test/fuzz/util.h:.* Class 'FuzzedFileProvider' has a constructor with 1 argument that is not explicit."
|
||||
"src/test/fuzz/util.h:.* Class 'FuzzedAutoFileProvider' has a constructor with 1 argument that is not explicit."
|
||||
"src/util/ref.h:.* Class 'Ref' has a constructor with 1 argument that is not explicit."
|
||||
"src/wallet/db.h:.* Class 'BerkeleyEnvironment' has a constructor with 1 argument that is not explicit."
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue