Browse Source

fixed a buffer detail and added fail function

master
Ludovic 'Archivist' Lagouardette 5 months ago
parent
commit
0143b6e714
2 changed files with 21 additions and 11 deletions
  1. +4
    -4
      include/gp/containers/buffer.hpp
  2. +17
    -7
      include/gp_config.hpp

+ 4
- 4
include/gp/containers/buffer.hpp View File

@ -213,14 +213,14 @@ namespace gp{
return hold_same_data<T>(this->slice_start(oth.size()), oth); return hold_same_data<T>(this->slice_start(oth.size()), oth);
} }
optional<T> front() {
optional<gp::reference_wrapper<T>> front() {
if(size() == 0) return nullopt; if(size() == 0) return nullopt;
return o">*begin();
return n">gp::ref(*slice_start(1).begin());
} }
optional<T> back() {
optional<gp::reference_wrapper<T>> back() {
if(size() == 0) return nullopt; if(size() == 0) return nullopt;
return o">*slice_end(1).begin();
return n">gp::ref(*slice_end(1).begin());
} }
}; };

+ 17
- 7
include/gp_config.hpp View File

@ -114,9 +114,6 @@ namespace gp_config{
*/ */
constexpr bool has_buffer_bounds = true; constexpr bool has_buffer_bounds = true;
//
//
//
/** /**
* @brief A value used to determine the strength used by random number generators * @brief A value used to determine the strength used by random number generators
* *
@ -129,7 +126,7 @@ namespace gp_config{
/** /**
* @brief an exception that represents an assertion failure * @brief an exception that represents an assertion failure
*/ */
struct assert_failure{
struct assert_failure : std::exception {
assert_failure(const char* reason) assert_failure(const char* reason)
: what_str{reason} : what_str{reason}
{} {}
@ -141,15 +138,28 @@ namespace gp_config{
* @brief UNUSED * @brief UNUSED
*/ */
constexpr size_t assert_buffer_size = 0; constexpr size_t assert_buffer_size = 0;
constexpr auto fail = [] [[noreturn]] (auto reason) noexcept(not has_exceptions) {
if constexpr (has_exceptions) {
throw assert_failure(reason);
} else {
volatile uint8_t n = 0;
{
failure_point:
n = n + 1;
goto failure_point;
}
}
};
/** /**
* @brief an assertion function * @brief an assertion function
*/ */
constexpr auto assertion = [](bool pred, const char* reason) -> void{
constexpr auto assertion = [](bool pred, const char* reason)
noexcept(std::is_nothrow_invocable_v<decltype(fail), decltype(reason)>) -> void {
if(!pred) { if(!pred) {
log_failure(reason); log_failure(reason);
if constexpr (has_exceptions)
throw assert_failure(reason);
fail(reason);
} }
}; };

Loading…
Cancel
Save