Skip to content

Commit

Permalink
C++20 corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Sep 21, 2024
1 parent 76f716c commit 5dd073c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/cpp20.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include $(config_dir)rel.mk

this_cxxflags += -std=c++20
1 change: 1 addition & 0 deletions src/utki/sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOFTWARE.

#pragma once

#include <algorithm>
#include <iterator>

#include "config.hpp"
Expand Down
5 changes: 5 additions & 0 deletions src/utki/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOFTWARE.

#include <fast_float/fast_float.h>

#include "config.hpp"
#include "debug.hpp"
#include "util.hpp"

Expand Down Expand Up @@ -357,7 +358,11 @@ void string_parser::skip_inclusive_until(char c)
char string_parser::skip_inclusive_until_one_of(utki::span<const char> c)
{
for (; !this->view.empty(); this->view = this->view.substr(1)) {
#if CFG_CPP >= 20
auto i = std::ranges::find(c, this->view.front());
#else
auto i = std::find(c.begin(), c.end(), this->view.front());
#endif
if (i != c.end()) {
this->view = this->view.substr(1);
return *i;
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/src/math.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <tst/check.hpp>
#include <tst/set.hpp>
#include <utki/config.hpp>
#include <utki/math.hpp>

namespace {
Expand All @@ -23,7 +24,13 @@ const tst::set set("math", [](tst::suite& suite) {
tst::check_lt(std::abs(std::exp((long double)(utki::log_2)) - 2), (long double)(epsilon), SL);

tst::check_eq(std::log((long double)(1)), (long double)(0), SL);
tst::check_lt(std::abs(std::log((long double)(2)) - (long double)(utki::log_2)), (long double)(epsilon), SL);
tst::check_lt(std::abs(
#if CFG_CPP >= 20
std::numbers::ln2_v<long double>
#else
std::log((long double)(2))
#endif
- (long double)(utki::log_2)), (long double)(epsilon), SL);

tst::check_eq(utki::rad_to_deg(float(utki::pi)), float(two_pi_degrees), SL);
tst::check_eq(utki::deg_to_rad(float(two_pi_degrees)), float(utki::pi), SL);
Expand Down

0 comments on commit 5dd073c

Please sign in to comment.