[ox/std] Fix problems in building with GCC 12

This commit is contained in:
Gary Talent 2022-05-25 01:07:48 -05:00
parent fd0d15b28e
commit 9417307a8e
4 changed files with 32 additions and 14 deletions

View File

@ -20,4 +20,14 @@ constexpr It find(It begin, It end, const T &value) {
return end;
}
template<typename It>
constexpr It find_if(It begin, It end, auto predicate) {
for (; begin != end; ++begin) {
if (predicate(*begin)) {
return begin;
}
}
return end;
}
}

View File

@ -15,21 +15,17 @@ namespace ox {
void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *panicMsg, [[maybe_unused]]const Error &err) noexcept {
#ifdef OX_USE_STDLIB
if (!std::is_constant_evaluated()) {
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
if (err.msg) {
oxErrf("\tError Message:\t{}\n", err.msg);
}
oxErrf("\tError Code:\t{}\n", static_cast<ErrorCode>(err));
if (err.file != nullptr) {
oxErrf("\tError Location:\t{}:{}\n", err.file, err.line);
}
printStackTrace(2);
oxTrace("panic").del("") << "Panic: " << panicMsg << " (" << file << ":" << line << ")";
std::abort();
} else {
assert(false);
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
if (err.msg) {
oxErrf("\tError Message:\t{}\n", err.msg);
}
oxErrf("\tError Code:\t{}\n", static_cast<ErrorCode>(err));
if (err.file != nullptr) {
oxErrf("\tError Location:\t{}:{}\n", err.file, err.line);
}
printStackTrace(2);
oxTrace("panic").del("") << "Panic: " << panicMsg << " (" << file << ":" << line << ")";
std::abort();
#endif
}

View File

@ -28,3 +28,14 @@ static_assert([] {
retval |= !(ox_lastIndexOf(testStr, 'a', ox_strlen(testStr)) == 3);
return retval == 0;
}(), "ox_lastIndexOf aaaa a");
#ifndef OX_USE_STDLIB
extern "C"
std::size_t strlen(const char *str) {
std::size_t len = 0;
for (; str[len]; len++);
return len;
}
#endif

View File

@ -9,6 +9,7 @@
#pragma once
#include "bit.hpp"
#include "error.hpp"
#include "initializerlist.hpp"
#include "iterator.hpp"
#include "math.hpp"