Skip to content

Commit

Permalink
Merge pull request laurynas-biveinis#688 from laurynas-biveinis/c++20…
Browse files Browse the repository at this point in the history
…-requires

Continue C++20 modernization
  • Loading branch information
laurynas-biveinis authored Feb 12, 2025
2 parents 4fa07e5 + 6127fc7 commit 3044234
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
5 changes: 2 additions & 3 deletions qsbr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,10 +1232,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
42 changes: 32 additions & 10 deletions test/db_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
// Should be the first include
#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 @@ -24,13 +21,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 @@ -83,13 +81,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 @@ -141,6 +136,11 @@ class [[nodiscard]] tree_verifier final {
UNODB_DETAIL_DISABLE_MSVC_WARNING(6326)

UNODB_DETAIL_DISABLE_MSVC_WARNING(26440)
// Replace std::enable_if_t in the next two methods with
// requires(std::is_same_v) when LLVM 15 is the oldest supported LLVM version.
// Earlier versions give errors of different declarations having identical
// mangled names.
// NOLINTBEGIN(modernize-use-constraints)
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) {
Expand All @@ -153,6 +153,7 @@ class [[nodiscard]] tree_verifier final {
const quiescent_state_on_scope_exit qsbr_after_get{};
UNODB_ASSERT_TRUE(test_db.insert(k, v));
}
// NOLINTEND(modernize-use-constraints)
UNODB_DETAIL_RESTORE_MSVC_WARNINGS()

void do_remove(key_type k, bool bypass_verifier) {
Expand Down Expand Up @@ -212,6 +213,11 @@ class [[nodiscard]] tree_verifier final {
}

UNODB_DETAIL_DISABLE_MSVC_WARNING(26440)
// Replace std::enable_if_t in the next two methods with
// requires(std::is_same_v) when LLVM 15 is the oldest supported LLVM version.
// Earlier versions give errors of different declarations having identical
// mangled names.
// NOLINTBEGIN(modernize-use-constraints)
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) {
Expand All @@ -224,6 +230,7 @@ class [[nodiscard]] tree_verifier final {
const quiescent_state_on_scope_exit qsbr_after_get{};
UNODB_ASSERT_FALSE(test_db.remove(absent_key));
}
// NOLINTEND(modernize-use-constraints)
UNODB_DETAIL_RESTORE_MSVC_WARNINGS()

UNODB_DETAIL_RESTORE_MSVC_WARNINGS()
Expand Down Expand Up @@ -331,6 +338,11 @@ class [[nodiscard]] tree_verifier final {
}
}

// Replace std::enable_if_t in the next four methods with
// requires(std::is_same_v) when LLVM 15 is the oldest supported LLVM version.
// Earlier versions give errors of different declarations having identical
// mangled names.
// NOLINTBEGIN(modernize-use-constraints)
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) {
Expand All @@ -356,6 +368,7 @@ class [[nodiscard]] tree_verifier final {
const quiescent_state_on_scope_exit qsbr_after_get{};
std::ignore = test_db.remove(k);
}
// NOLINTEND(modernize-use-constraints)

UNODB_DETAIL_DISABLE_MSVC_WARNING(6326)
void attempt_remove_missing_keys(
Expand All @@ -378,6 +391,11 @@ class [[nodiscard]] tree_verifier final {
}
UNODB_DETAIL_RESTORE_MSVC_WARNINGS()

// Replace std::enable_if_t in the next two methods with
// requires(std::is_same_v) when LLVM 15 is the oldest supported LLVM version.
// Earlier versions give errors of different declarations having identical
// mangled names.
// NOLINTBEGIN(modernize-use-constraints)
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))) {
Expand All @@ -390,6 +408,7 @@ class [[nodiscard]] tree_verifier final {
const quiescent_state_on_scope_exit qsbr_after_get{};
std::ignore = test_db.get(k);
}
// NOLINTEND(modernize-use-constraints)

UNODB_DETAIL_DISABLE_MSVC_WARNING(26445)
void check_present_values() const {
Expand Down Expand Up @@ -471,6 +490,9 @@ class [[nodiscard]] tree_verifier final {

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

tree_verifier(const tree_verifier &) = delete;
tree_verifier &operator=(const tree_verifier &) = delete;

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

0 comments on commit 3044234

Please sign in to comment.