Skip to content

Commit 4cdf85a

Browse files
committed
log: Make common log functions consteval.
1 parent 575fc61 commit 4cdf85a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

libopenage/log/message.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
1+
// Copyright 2015-2024 the openage authors. See copying.md for legal info.
22

33
#pragma once
44

@@ -11,7 +11,7 @@
1111
#include <string>
1212

1313
#include "../util/compiler.h"
14-
#include "../util/constexpr.h"
14+
#include "../util/consteval.h"
1515
#include "../util/stringformatter.h"
1616
#include "config.h"
1717
#include "logsink.h"
@@ -165,7 +165,7 @@ class OAAPI MessageBuilder : public util::StringFormatter<MessageBuilder> {
165165
// for use with existing log::level objects
166166
#define MSG_LVLOBJ(LVLOBJ) \
167167
::openage::log::MessageBuilder( \
168-
::openage::util::constexpr_::strip_prefix( \
168+
::openage::util::consteval_::strip_prefix( \
169169
__FILE__, \
170170
::openage::config::buildsystem_sourcefile_dir), \
171171
__LINE__, \

libopenage/util/constexpr.h renamed to libopenage/util/consteval.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77

88
/**
9-
* This namespace contains constexpr functions, i.e. C++14 functions that are designed
10-
* to run at compile-time.
9+
* This namespace contains consteval functions, i.e. C++20 functions that are designed
10+
* to be evaluated at compile-time.
1111
*/
12-
namespace openage::util::constexpr_ {
12+
namespace openage::util::consteval_ {
1313

1414
/**
1515
* Returns true IFF the string literals have equal content.
1616
*/
17-
constexpr bool streq(const char *a, const char *b) {
17+
consteval bool streq(const char *a, const char *b) {
1818
for (; *a == *b; ++a, ++b) {
1919
if (*a == '\0') {
2020
return true;
@@ -27,7 +27,7 @@ constexpr bool streq(const char *a, const char *b) {
2727
/**
2828
* Returns the length of the string literal, excluding the terminating NULL byte.
2929
*/
30-
constexpr size_t strlen(const char *str) {
30+
consteval size_t strlen(const char *str) {
3131
for (size_t len = 0;; ++len) {
3232
if (str[len] == '\0') {
3333
return len;
@@ -56,7 +56,7 @@ struct truncated_string_literal {
5656
*
5757
* Raises 'false' if str doesn't end in the given suffix.
5858
*/
59-
constexpr truncated_string_literal get_prefix(const char *str, const char *suffix) {
59+
consteval truncated_string_literal get_prefix(const char *str, const char *suffix) {
6060
if (strlen(str) < strlen(suffix)) {
6161
// suffix is longer than str
6262
throw false;
@@ -74,14 +74,14 @@ constexpr truncated_string_literal get_prefix(const char *str, const char *suffi
7474
/**
7575
* Creates a truncated_string_literal from a regular string literal.
7676
*/
77-
constexpr truncated_string_literal create_truncated_string_literal(const char *str) {
77+
consteval truncated_string_literal create_truncated_string_literal(const char *str) {
7878
return truncated_string_literal{str, strlen(str)};
7979
}
8080

8181
/**
8282
* Tests whether a string literal starts with the given prefix.
8383
*/
84-
constexpr bool has_prefix(const char *str, const truncated_string_literal prefix) {
84+
consteval bool has_prefix(const char *str, const truncated_string_literal prefix) {
8585
for (size_t pos = 0; pos < prefix.length; ++pos) {
8686
if (str[pos] != prefix.literal[pos]) {
8787
return false;
@@ -96,7 +96,7 @@ constexpr bool has_prefix(const char *str, const truncated_string_literal prefix
9696
*
9797
* If the string literal doesn't have that prefix, returns the string literal itself.
9898
*/
99-
constexpr const char *strip_prefix(const char *str, const truncated_string_literal prefix) {
99+
consteval const char *strip_prefix(const char *str, const truncated_string_literal prefix) {
100100
if (has_prefix(str, prefix)) {
101101
return str + prefix.length;
102102
}
@@ -111,8 +111,8 @@ constexpr const char *strip_prefix(const char *str, const truncated_string_liter
111111
*
112112
* If the string literal doesn't have that prefix, returns the string literal itself.
113113
*/
114-
constexpr const char *strip_prefix(const char *str, const char *prefix) {
114+
consteval const char *strip_prefix(const char *str, const char *prefix) {
115115
return strip_prefix(str, create_truncated_string_literal(prefix));
116116
}
117117

118-
} // namespace openage::util::constexpr_
118+
} // namespace openage::util::consteval_

0 commit comments

Comments
 (0)