Skip to content

Commit 43ed978

Browse files
committed
Update throw macro
1 parent 7cef9c6 commit 43ed978

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

include/beman/inplace_vector/inplace_vector.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
// Artifact from previous implementation, can be used as hints for optimizer
2222
#define IV_EXPECT(EXPR)
2323

24+
#ifndef BEMAN_IV_THROW_OR_ABORT
2425
#if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
25-
#ifndef BEMAN_IV_THROW
2626
#include <cstdlib> // for abort
27-
#define BEMAN_IV_THROW(x) abort()
28-
#endif
27+
#define BEMAN_IV_THROW_OR_ABORT(x) abort()
2928
#else
3029
#include <stdexcept> // for length_error
31-
#define BEMAN_IV_THROW(x) throw x
30+
#define BEMAN_IV_THROW_OR_ABORT(x) throw x
31+
#endif
3232
#endif
3333

3434
// beman::from_range_t
@@ -269,7 +269,7 @@ struct inplace_vector
269269
static constexpr size_type capacity() noexcept { return N; }
270270
constexpr void reserve(size_type n) {
271271
if (n > N) [[unlikely]] {
272-
BEMAN_IV_THROW(std::bad_alloc());
272+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
273273
}
274274
}
275275
constexpr void shrink_to_fit() {}
@@ -361,7 +361,7 @@ struct inplace_vector
361361
requires(std::constructible_from<T, Args...>)
362362
{
363363
if (!try_emplace_back(std::forward<Args>(args)...)) [[unlikely]] {
364-
BEMAN_IV_THROW(std::bad_alloc());
364+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
365365
}
366366
return back();
367367
}
@@ -406,12 +406,12 @@ struct inplace_vector
406406
{
407407
if constexpr (std::ranges::sized_range<R>) {
408408
if (size() + std::ranges::size(rg) > capacity()) [[unlikely]] {
409-
BEMAN_IV_THROW(std::bad_alloc());
409+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
410410
}
411411
}
412412
for (auto &&e : rg) {
413413
if (size() == capacity()) [[unlikely]] {
414-
BEMAN_IV_THROW(std::bad_alloc());
414+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
415415
}
416416
emplace_back(std::forward<decltype(e)>(e));
417417
}
@@ -451,7 +451,7 @@ struct inplace_vector
451451
if constexpr (std::random_access_iterator<InputIterator>) {
452452
if (size() + static_cast<size_type>(std::distance(first, last)) >
453453
capacity()) [[unlikely]] {
454-
BEMAN_IV_THROW(std::bad_alloc());
454+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
455455
}
456456
}
457457
auto b = end();
@@ -569,7 +569,7 @@ struct inplace_vector
569569
if (sz == size())
570570
return;
571571
else if (sz > N) [[unlikely]] {
572-
BEMAN_IV_THROW(std::bad_alloc());
572+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
573573
} else if (sz > size())
574574
insert(end(), sz - size(), c);
575575
else {
@@ -583,7 +583,7 @@ struct inplace_vector
583583
if (sz == size())
584584
return;
585585
else if (sz > N) [[unlikely]] {
586-
BEMAN_IV_THROW(std::bad_alloc());
586+
BEMAN_IV_THROW_OR_ABORT(std::bad_alloc());
587587
} else if (sz > size()) {
588588
while (size() != sz)
589589
emplace_back(T{});
@@ -595,13 +595,13 @@ struct inplace_vector
595595

596596
constexpr reference at(size_type pos) {
597597
if (pos >= size()) [[unlikely]] {
598-
BEMAN_IV_THROW(std::out_of_range("inplace_vector::at"));
598+
BEMAN_IV_THROW_OR_ABORT(std::out_of_range("inplace_vector::at"));
599599
}
600600
return details::inplace_vector::index(*this, pos);
601601
}
602602
constexpr const_reference at(size_type pos) const {
603603
if (pos >= size()) [[unlikely]] {
604-
BEMAN_IV_THROW(std::out_of_range("inplace_vector::at"));
604+
BEMAN_IV_THROW_OR_ABORT(std::out_of_range("inplace_vector::at"));
605605
}
606606
return details::inplace_vector::index(*this, pos);
607607
}

tests/beman/inplace_vector/noexceptions.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <array>
22

33
bool abort_called = false;
4-
#define BEMAN_IV_THROW(x) abort_called = true;
4+
#define BEMAN_IV_THROW_OR_ABORT(x) abort_called = true;
55

66
#include "gtest_setup.hpp"
77

0 commit comments

Comments
 (0)