Skip to content

Commit d81a674

Browse files
qudixgithub-actions[bot]
authored andcommitted
maintenance
1 parent b3c8bff commit d81a674

3 files changed

Lines changed: 88 additions & 90 deletions

File tree

include/REX/BASE.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
#include <tuple>
5656
#include <type_traits>
5757
#include <typeinfo>
58-
#include <unordered_set>
5958
#include <unordered_map>
59+
#include <unordered_set>
6060
#include <utility>
6161
#include <variant>
6262
#include <vector>

include/REX/REX/AtomicRef.h

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,42 @@
44

55
namespace REX
66
{
7-
template <class T>
8-
class TAtomicRef :
9-
public std::atomic_ref<T>
10-
{
11-
private:
12-
using super = std::atomic_ref<T>;
13-
14-
public:
15-
using value_type = typename super::value_type;
16-
17-
explicit TAtomicRef(volatile T& a_obj) noexcept(std::is_nothrow_constructible_v<super, value_type&>) :
18-
super(const_cast<value_type&>(a_obj))
19-
{}
20-
21-
using super::super;
22-
using super::operator=;
23-
};
24-
25-
template <class T>
26-
TAtomicRef(volatile T&) -> TAtomicRef<T>;
27-
28-
template class TAtomicRef<std::int8_t>;
29-
template class TAtomicRef<std::uint8_t>;
30-
template class TAtomicRef<std::int16_t>;
31-
template class TAtomicRef<std::uint16_t>;
32-
template class TAtomicRef<std::int32_t>;
33-
template class TAtomicRef<std::uint32_t>;
34-
template class TAtomicRef<std::int64_t>;
35-
template class TAtomicRef<std::uint64_t>;
36-
37-
static_assert(TAtomicRef<std::int8_t>::is_always_lock_free);
38-
static_assert(TAtomicRef<std::uint8_t>::is_always_lock_free);
39-
static_assert(TAtomicRef<std::int16_t>::is_always_lock_free);
40-
static_assert(TAtomicRef<std::uint16_t>::is_always_lock_free);
41-
static_assert(TAtomicRef<std::int32_t>::is_always_lock_free);
42-
static_assert(TAtomicRef<std::uint32_t>::is_always_lock_free);
43-
static_assert(TAtomicRef<std::int64_t>::is_always_lock_free);
44-
static_assert(TAtomicRef<std::uint64_t>::is_always_lock_free);
7+
template <class T>
8+
class TAtomicRef :
9+
public std::atomic_ref<T>
10+
{
11+
private:
12+
using super = std::atomic_ref<T>;
13+
14+
public:
15+
using value_type = typename super::value_type;
16+
17+
explicit TAtomicRef(volatile T& a_obj) noexcept(std::is_nothrow_constructible_v<super, value_type&>) :
18+
super(const_cast<value_type&>(a_obj))
19+
{}
20+
21+
using super::super;
22+
using super::operator=;
23+
};
24+
25+
template <class T>
26+
TAtomicRef(volatile T&) -> TAtomicRef<T>;
27+
28+
template class TAtomicRef<std::int8_t>;
29+
template class TAtomicRef<std::uint8_t>;
30+
template class TAtomicRef<std::int16_t>;
31+
template class TAtomicRef<std::uint16_t>;
32+
template class TAtomicRef<std::int32_t>;
33+
template class TAtomicRef<std::uint32_t>;
34+
template class TAtomicRef<std::int64_t>;
35+
template class TAtomicRef<std::uint64_t>;
36+
37+
static_assert(TAtomicRef<std::int8_t>::is_always_lock_free);
38+
static_assert(TAtomicRef<std::uint8_t>::is_always_lock_free);
39+
static_assert(TAtomicRef<std::int16_t>::is_always_lock_free);
40+
static_assert(TAtomicRef<std::uint16_t>::is_always_lock_free);
41+
static_assert(TAtomicRef<std::int32_t>::is_always_lock_free);
42+
static_assert(TAtomicRef<std::uint32_t>::is_always_lock_free);
43+
static_assert(TAtomicRef<std::int64_t>::is_always_lock_free);
44+
static_assert(TAtomicRef<std::uint64_t>::is_always_lock_free);
4545
}

include/REX/REX/ScopeExit.h

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,62 @@
44

55
namespace REX
66
{
7-
template <class EF>
8-
requires(std::invocable<std::remove_reference_t<EF>>)
9-
class TScopeExit
10-
{
11-
public:
12-
template <class Fn>
13-
explicit TScopeExit(Fn&& a_fn)
14-
noexcept(std::is_nothrow_constructible_v<EF, Fn> ||
15-
std::is_nothrow_constructible_v<EF, Fn&>)
16-
requires(!std::is_same_v<std::remove_cvref_t<Fn>, TScopeExit> &&
17-
std::is_constructible_v<EF, Fn>)
18-
{
19-
static_assert(std::invocable<Fn>);
7+
template <class EF>
8+
requires(std::invocable<std::remove_reference_t<EF>>)
9+
class TScopeExit
10+
{
11+
public:
12+
template <class Fn>
13+
explicit TScopeExit(Fn&& a_fn) noexcept(std::is_nothrow_constructible_v<EF, Fn> ||
14+
std::is_nothrow_constructible_v<EF, Fn&>)
15+
requires(!std::is_same_v<std::remove_cvref_t<Fn>, TScopeExit> &&
16+
std::is_constructible_v<EF, Fn>)
17+
{
18+
static_assert(std::invocable<Fn>);
2019

21-
if constexpr (!std::is_lvalue_reference_v<Fn> &&
22-
std::is_nothrow_constructible_v<EF, Fn>) {
23-
_fn.emplace(std::forward<Fn>(a_fn));
24-
} else {
25-
_fn.emplace(a_fn);
26-
}
27-
}
20+
if constexpr (!std::is_lvalue_reference_v<Fn> &&
21+
std::is_nothrow_constructible_v<EF, Fn>) {
22+
_fn.emplace(std::forward<Fn>(a_fn));
23+
} else {
24+
_fn.emplace(a_fn);
25+
}
26+
}
2827

29-
TScopeExit(TScopeExit&& a_rhs)
30-
noexcept(std::is_nothrow_move_constructible_v<EF> ||
31-
std::is_nothrow_copy_constructible_v<EF>)
32-
requires(std::is_nothrow_move_constructible_v<EF> ||
33-
std::is_copy_constructible_v<EF>)
34-
{
35-
static_assert(!(std::is_nothrow_move_constructible_v<EF> && !std::is_move_constructible_v<EF>));
36-
static_assert(!(!std::is_nothrow_move_constructible_v<EF> && !std::is_copy_constructible_v<EF>));
28+
TScopeExit(TScopeExit&& a_rhs) noexcept(std::is_nothrow_move_constructible_v<EF> ||
29+
std::is_nothrow_copy_constructible_v<EF>)
30+
requires(std::is_nothrow_move_constructible_v<EF> ||
31+
std::is_copy_constructible_v<EF>)
32+
{
33+
static_assert(!(std::is_nothrow_move_constructible_v<EF> && !std::is_move_constructible_v<EF>));
34+
static_assert(!(!std::is_nothrow_move_constructible_v<EF> && !std::is_copy_constructible_v<EF>));
3735

38-
if (a_rhs.active()) {
39-
if constexpr (std::is_nothrow_move_constructible_v<EF>) {
40-
_fn.emplace(std::forward<EF>(*a_rhs._fn));
41-
} else {
42-
_fn.emplace(a_rhs._fn);
43-
}
44-
a_rhs.release();
45-
}
46-
}
36+
if (a_rhs.active()) {
37+
if constexpr (std::is_nothrow_move_constructible_v<EF>) {
38+
_fn.emplace(std::forward<EF>(*a_rhs._fn));
39+
} else {
40+
_fn.emplace(a_rhs._fn);
41+
}
42+
a_rhs.release();
43+
}
44+
}
4745

48-
TScopeExit(const TScopeExit&) = delete;
46+
TScopeExit(const TScopeExit&) = delete;
4947

50-
~TScopeExit() noexcept
51-
{
52-
if (_fn.has_value()) {
53-
(*_fn)();
54-
}
55-
}
48+
~TScopeExit() noexcept
49+
{
50+
if (_fn.has_value()) {
51+
(*_fn)();
52+
}
53+
}
5654

57-
void release() noexcept { _fn.reset(); }
55+
void release() noexcept { _fn.reset(); }
5856

59-
private:
60-
[[nodiscard]] bool active() const noexcept { return _fn.has_value(); }
57+
private:
58+
[[nodiscard]] bool active() const noexcept { return _fn.has_value(); }
6159

62-
std::optional<std::remove_reference_t<EF>> _fn;
63-
};
60+
std::optional<std::remove_reference_t<EF>> _fn;
61+
};
6462

65-
template <class EF>
66-
TScopeExit(EF) -> TScopeExit<EF>;
63+
template <class EF>
64+
TScopeExit(EF) -> TScopeExit<EF>;
6765
}

0 commit comments

Comments
 (0)