Procházet zdrojové kódy

fixed a buffer detail and added fail function

master
Ludovic 'Archivist' Lagouardette před 1 rokem
rodič
revize
0143b6e714
2 změnil soubory, kde provedl 21 přidání a 11 odebrání
  1. +4
    -4
      include/gp/containers/buffer.hpp
  2. +17
    -7
      include/gp_config.hpp

+ 4
- 4
include/gp/containers/buffer.hpp Zobrazit soubor

@ -213,14 +213,14 @@ namespace gp{
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;
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;
return o">*slice_end(1).begin();
return n">gp::ref(*slice_end(1).begin());
}
};

+ 17
- 7
include/gp_config.hpp Zobrazit soubor

@ -114,9 +114,6 @@ namespace gp_config{
*/
constexpr bool has_buffer_bounds = true;
//
//
//
/**
* @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
*/
struct assert_failure{
struct assert_failure : std::exception {
assert_failure(const char* reason)
: what_str{reason}
{}
@ -141,15 +138,28 @@ namespace gp_config{
* @brief UNUSED
*/
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
*/
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) {
log_failure(reason);
if constexpr (has_exceptions)
throw assert_failure(reason);
fail(reason);
}
};

Načítá se…
Zrušit
Uložit