Skip to content

Commit

Permalink
Continue C++20 modernization
Browse files Browse the repository at this point in the history
- qsbr.hpp: replace std::enable_if_t with requires
- db_test_utils.hpp: replace std::enable_if_t with requires, iterator pairs
  with ranges, update includes, fix clang-tidy warning on const field.
  • Loading branch information
laurynas-biveinis committed Feb 7, 2025
1 parent 364dee0 commit 1a89f5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
5 changes: 2 additions & 3 deletions qsbr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,10 +1241,9 @@ class [[nodiscard]] qsbr_thread : public std::thread {
public:
using thread::thread;

template <typename Function, typename... Args,
class = std::enable_if_t<
!std::is_same_v<remove_cvref_t<Function>, qsbr_thread>>>
template <typename Function, typename... Args>
explicit qsbr_thread(Function &&f, Args &&...args)
requires(!std::is_same_v<remove_cvref_t<Function>, qsbr_thread>)
: std::thread{make_qsbr_thread(std::forward<Function>(f),
std::forward<Args>(args)...)} {}

Expand Down
67 changes: 27 additions & 40 deletions test/db_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
// container internal structure layouts and that is Not Good.
#include "global.hpp" // IWYU pragma: keep

// IWYU pragma: no_include <__fwd/sstream.h>
// IWYU pragma: no_include <__ostream/basic_ostream.h>
// IWYU pragma: no_include <iterator>
// IWYU pragma: no_include <iomanip>
// IWYU pragma: no_include <string>
// IWYU pragma: no_include "gmock/gmock.h"
// IWYU pragma: no_include "gtest/gtest.h"

#include <algorithm>
#include <array>
Expand All @@ -31,13 +28,14 @@
#include <tuple>
#include <type_traits>

#include <gmock/gmock.h> // IWYU pragma: keep
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "gtest_utils.hpp"

#include "art.hpp"
#include "art_common.hpp"
#include "art_internal.hpp"
#include "assert.hpp"
#include "mutex_art.hpp"
#include "node_type.hpp"
Expand Down Expand Up @@ -90,13 +88,10 @@ void assert_value_eq(const typename Db::get_result &result,
if constexpr (std::is_same_v<Db, unodb::mutex_db<typename Db::key_type>>) {
UNODB_DETAIL_ASSERT(result.second.owns_lock());
UNODB_DETAIL_ASSERT(result.first.has_value());
UNODB_ASSERT_TRUE(std::equal(std::cbegin(*result.first),
std::cend(*result.first),
std::cbegin(expected), std::cend(expected)));
UNODB_ASSERT_TRUE(std::ranges::equal(*result.first, expected));
} else {
UNODB_DETAIL_ASSERT(result.has_value());
UNODB_ASSERT_TRUE(std::equal(std::cbegin(*result), std::cend(*result),
std::cbegin(expected), std::cend(expected)));
UNODB_ASSERT_TRUE(std::ranges::equal(*result, expected));
}
}
UNODB_DETAIL_RESTORE_MSVC_WARNINGS()
Expand Down Expand Up @@ -148,15 +143,13 @@ class [[nodiscard]] tree_verifier final {
UNODB_DETAIL_DISABLE_MSVC_WARNING(6326)

UNODB_DETAIL_DISABLE_MSVC_WARNING(26440)
template <class Db2 = Db>
std::enable_if_t<!std::is_same_v<Db2, unodb::olc_db<key_type>>, void>
do_insert(key_type k, unodb::value_view v) {
void do_insert(key_type k, unodb::value_view v)
requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) {
UNODB_ASSERT_TRUE(test_db.insert(k, v));
}

template <class Db2 = Db>
std::enable_if_t<std::is_same_v<Db2, unodb::olc_db<key_type>>, void>
do_insert(key_type k, unodb::value_view v) {
void do_insert(key_type k, unodb::value_view v)
requires(std::is_same_v<Db, unodb::olc_db<key_type>>) {
const quiescent_state_on_scope_exit qsbr_after_get{};
UNODB_ASSERT_TRUE(test_db.insert(k, v));
}
Expand Down Expand Up @@ -219,15 +212,13 @@ class [[nodiscard]] tree_verifier final {
}

UNODB_DETAIL_DISABLE_MSVC_WARNING(26440)
template <class Db2 = Db>
std::enable_if_t<!std::is_same_v<Db2, unodb::olc_db<key_type>>, void>
do_try_remove_missing_key(key_type absent_key) {
void do_try_remove_missing_key(key_type absent_key)
requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) {
UNODB_ASSERT_FALSE(test_db.remove(absent_key));
}

template <class Db2 = Db>
std::enable_if_t<std::is_same_v<Db2, unodb::olc_db<key_type>>, void>
do_try_remove_missing_key(key_type absent_key) {
void do_try_remove_missing_key(key_type absent_key)
requires(std::is_same_v<Db, unodb::olc_db<key_type>>) {
const quiescent_state_on_scope_exit qsbr_after_get{};
UNODB_ASSERT_FALSE(test_db.remove(absent_key));
}
Expand Down Expand Up @@ -338,28 +329,24 @@ class [[nodiscard]] tree_verifier final {
}
}

template <class Db2 = Db>
std::enable_if_t<!std::is_same_v<Db2, unodb::olc_db<key_type>>, void> remove(
key_type k, bool bypass_verifier = false) {
void remove(key_type k, bool bypass_verifier = false)
requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) {
do_remove(k, bypass_verifier);
}

template <class Db2 = Db>
std::enable_if_t<std::is_same_v<Db2, unodb::olc_db<key_type>>, void> remove(
key_type k, bool bypass_verifier = false) {
void remove(key_type k, bool bypass_verifier = false)
requires(std::is_same_v<Db, unodb::olc_db<key_type>>) {
const quiescent_state_on_scope_exit qsbr_after_get{};
do_remove(k, bypass_verifier);
}

template <class Db2 = Db>
std::enable_if_t<!std::is_same_v<Db2, unodb::olc_db<key_type>>, void>
try_remove(key_type k) {
void try_remove(key_type k)
requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) {
std::ignore = test_db.remove(k);
}

template <class Db2 = Db>
std::enable_if_t<std::is_same_v<Db2, unodb::olc_db<key_type>>, void>
try_remove(key_type k) {
void try_remove(key_type k)
requires(std::is_same_v<Db, unodb::olc_db<key_type>>) {
const quiescent_state_on_scope_exit qsbr_after_get{};
std::ignore = test_db.remove(k);
}
Expand All @@ -385,15 +372,13 @@ class [[nodiscard]] tree_verifier final {
}
UNODB_DETAIL_RESTORE_MSVC_WARNINGS()

template <class Db2 = Db>
std::enable_if_t<!std::is_same_v<Db2, unodb::olc_db<key_type>>, void> try_get(
key_type k) const noexcept(noexcept(this->test_db.get(k))) {
void try_get(key_type k) const noexcept(noexcept(this->test_db.get(k)))
requires(!std::is_same_v<Db, unodb::olc_db<key_type>>) {
std::ignore = test_db.get(k);
}

template <class Db2 = Db>
std::enable_if_t<std::is_same_v<Db2, unodb::olc_db<key_type>>, void> try_get(
key_type k) const noexcept(noexcept(this->test_db.get(k))) {
void try_get(key_type k) const noexcept(noexcept(this->test_db.get(k)))
requires(std::is_same_v<Db, unodb::olc_db<key_type>>) {
const quiescent_state_on_scope_exit qsbr_after_get{};
std::ignore = test_db.get(k);
}
Expand Down Expand Up @@ -478,6 +463,8 @@ class [[nodiscard]] tree_verifier final {

[[nodiscard, gnu::pure]] constexpr Db &get_db() noexcept { return test_db; }

tree_verifier(const tree_verifier &) = delete;

private:
// Custom comparator is required for key_view.
struct comparator {
Expand Down

0 comments on commit 1a89f5f

Please sign in to comment.