From 7c29a931fa087da8852a6b00e363b123b34f210c Mon Sep 17 00:00:00 2001 From: no92 Date: Fri, 27 Sep 2024 00:26:55 +0200 Subject: [PATCH 1/2] manual_box: avoid relying on the internal layout of aligned_storage --- include/frg/manual_box.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/frg/manual_box.hpp b/include/frg/manual_box.hpp index c41cab1..3a4bb25 100644 --- a/include/frg/manual_box.hpp +++ b/include/frg/manual_box.hpp @@ -18,14 +18,14 @@ class manual_box { template void initialize(Args &&... args) { FRG_ASSERT(!_initialized); - new(&_storage) T(std::forward(args)...); + new(&_storage.buffer) T(std::forward(args)...); _initialized = true; } template void construct_with(F f) { FRG_ASSERT(!_initialized); - new(&_storage) T{f()}; + new(&_storage.buffer) T{f()}; _initialized = true; } @@ -37,7 +37,7 @@ class manual_box { T *get() { FRG_ASSERT(_initialized); - return std::launder(reinterpret_cast(&_storage)); + return std::launder(reinterpret_cast(&_storage.buffer)); } bool valid() { From 09aa80108f8cf83a7c254096c9c289c28ccc4e78 Mon Sep 17 00:00:00 2001 From: no92 Date: Fri, 27 Sep 2024 10:28:39 +0200 Subject: [PATCH 2/2] utility: implement `abs` function --- include/frg/utility.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/frg/utility.hpp b/include/frg/utility.hpp index 8003d19..5953cf5 100644 --- a/include/frg/utility.hpp +++ b/include/frg/utility.hpp @@ -15,6 +15,12 @@ const T &max(const T &a, const T &b) { return (a < b) ? b : a; } +template +requires (T(-1) < T(0)) +const T abs(const T v) { + return (v < 0) ? -v : v; +} + template struct composition : private T { static T &get(composition *p) {