Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set CMake standard to 23 #1210

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(QLever C CXX)
# C/C++ Versions
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand Down
14 changes: 6 additions & 8 deletions src/util/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ namespace ad_utility {
*/
template <typename Container, typename T>
constexpr bool contains(Container&& container, const T& element) {
// Overload for types like std::string that have a `find` member function
if constexpr (ad_utility::isSimilar<Container, std::string> ||
ad_utility::isSimilar<Container, std::string_view>) {
return container.find(element) != container.npos;
} else {
return std::ranges::find(std::begin(container), std::end(container),
element) != std::end(container);
}
static_assert(
!ad_utility::isSimilar<Container, std::string> &&
!ad_utility::isSimilar<Container, std::string_view>,
"String and string_view can use member function contains since C++23");
return std::ranges::find(std::begin(container), std::end(container),
element) != std::end(container);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/util/MemorySize/MemorySize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MemorySize MemorySize::parse(std::string_view str) {
auto unitString = matcher.get<"unit">().to_view();
switch (std::tolower(unitString.at(0))) {
case 'b':
if (ad_utility::contains(amountString, '.')) {
if (amountString.contains('.')) {
throw std::runtime_error(absl::StrCat(
"'", str,
"' could not be parsed as a memory size. When using bytes as "
Expand Down
31 changes: 0 additions & 31 deletions test/AlgorithmTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,6 @@ TEST(Algorithm, Contains) {
7,
},
[&v](const auto& el) { return contains(v, el); }));

auto testStringLike = []<typename StringLike>() {
StringLike s{"hal"};
{
std::vector<std::string> substrings{"h", "a", "l", "ha", "al", "hal"};
ASSERT_TRUE(std::ranges::all_of(
substrings, [&s](const auto& el) { return contains(s, el); }));
std::vector<std::string> noSubstrings{"x", "hl", "hel"};
ASSERT_TRUE(std::ranges::none_of(
noSubstrings, [&s](const auto& el) { return contains(s, el); }));
}
{
std::vector<std::string_view> substrings{"h", "a", "l",
"ha", "al", "hal"};
ASSERT_TRUE(std::ranges::all_of(
substrings, [&s](const auto& el) { return contains(s, el); }));
std::vector<std::string_view> noSubstrings{"x", "hl", "hel"};
ASSERT_TRUE(std::ranges::none_of(
noSubstrings, [&s](const auto& el) { return contains(s, el); }));
}

std::vector<char> subchars{'h', 'a', 'l'};
ASSERT_TRUE(std::ranges::all_of(
subchars, [&s](const auto& el) { return contains(s, el); }));

std::vector<char> noSubchars{'i', 'b', 'm'};
ASSERT_TRUE(std::ranges::none_of(
noSubchars, [&s](const auto& el) { return contains(s, el); }));
};
testStringLike.template operator()<std::string>();
testStringLike.template operator()<std::string_view>();
}

// _____________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion test/ExceptionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ auto makeMatcher = [](const std::string& condition,
};

void checkContains(const std::exception& e, std::string_view substring) {
ASSERT_TRUE(ad_utility::contains(std::string_view{e.what()}, substring));
ASSERT_TRUE(std::string_view{e.what()}.contains(substring));
}
} // namespace

Expand Down
Loading