Skip to content

Commit 1201020

Browse files
committed
fix: update plg includes
1 parent f63b395 commit 1201020

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2944
-2962
lines changed

include/plg/allocator.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,23 @@ namespace plg {
143143
// asan_annotate_container_with_allocator determines whether containers with custom allocators are annotated. This is
144144
// a public customization point to disable annotations if the custom allocator assumes that the memory isn't poisoned.
145145
// See the https://libcxx.llvm.org/UsingLibcxx.html#turning-off-asan-annotation-in-containers for more information.
146-
#if __has_feature(address_sanitizer)
146+
#if PLUGIFY_INSTRUMENTED_WITH_ASAN
147147
template <class Alloc>
148148
struct asan_annotate_container_with_allocator : std::true_type {};
149-
#endif
149+
#endif // PLUGIFY_INSTRUMENTED_WITH_ASAN
150150

151151
// Annotate a contiguous range.
152152
// [__first_storage, __last_storage) is the allocated memory region,
153153
// __old_last_contained is the previously last allowed (unpoisoned) element, and
154154
// __new_last_contained is the new last allowed (unpoisoned) element.
155155
template <class Allocator>
156-
void annotate_contiguous_container(
156+
constexpr void annotate_contiguous_container(
157157
[[maybe_unused]] const void* first_storage,
158158
[[maybe_unused]] const void* last_storage,
159159
[[maybe_unused]] const void* old_last_contained,
160160
[[maybe_unused]] const void* new_last_contained
161161
) {
162-
#if __has_feature(address_sanitizer)
162+
#if PLUGIFY_INSTRUMENTED_WITH_ASAN
163163
if (!std::is_constant_evaluated()
164164
&& asan_annotate_container_with_allocator<Allocator>::value
165165
&& first_storage != nullptr) {
@@ -170,6 +170,6 @@ namespace plg {
170170
new_last_contained
171171
);
172172
}
173-
#endif
173+
#endif // PLUGIFY_INSTRUMENTED_WITH_ASAN
174174
}
175175
} // namespace plg

include/plg/concepts.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <concepts>
45
#include <memory>
56
#include <type_traits>

include/plg/config.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# define __has_builtin(x) 0
1717
#endif
1818

19-
#ifndef __builtin_constant_p
19+
#if !__has_builtin(__builtin_constant_p)
2020
# define __builtin_constant_p(x) std::is_constant_evaluated()
2121
#endif
2222

@@ -29,11 +29,7 @@
2929
# define PLUGIFY_ASSERT(cond, mesg) assert((cond) && (mesg))
3030
#endif
3131

32-
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
33-
# include <sanitizer/asan_interface.h>
34-
#endif
35-
36-
#define PLUGIFY_HAS_EXCEPTIONS __cpp_exceptions || _CPPUNWIND || __EXCEPTIONS
32+
#define PLUGIFY_HAS_EXCEPTIONS __cpp_exceptions || _CPPUNWIND || __EXCEPTIONS
3733
#if PLUGIFY_HAS_EXCEPTIONS
3834
# include <stdexcept>
3935
# include <type_traits>
@@ -47,11 +43,20 @@ namespace plg {
4743
}
4844
}
4945
} // namespace plg
50-
# define PLUGIFY_THROW(str, exp, ...) ::plg::throw_exception<exp>(str, ##__VA_ARGS__);
46+
# define PLUGIFY_THROW(str, exp, ...) ::plg::throw_exception<exp>(str __VA_OPT__(,) __VA_ARGS__);
5147
#else
5248
# include <cstdlib>
5349
# include <cstdio>
54-
# define PLUGIFY_THROW(str, ...) { std::fputs(str "\n", stderr); std::abort(); }
50+
# define PLUGIFY_THROW(str, ...) \
51+
std::fputs(str "\n", stderr); \
52+
std::abort();
53+
#endif
54+
55+
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
56+
# define PLUGIFY_INSTRUMENTED_WITH_ASAN 1
57+
# include <sanitizer/asan_interface.h>
58+
#else
59+
# define PLUGIFY_INSTRUMENTED_WITH_ASAN 0
5560
#endif
5661

5762
# define PLUGIFY_COMPILER_MAKE_VERSION2(version, sp) ((version) * 100 + (sp))

include/plg/enum.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ namespace plg {
1717
template <std::size_t N>
1818
struct static_string {
1919
constexpr static_string(std::string_view sv) noexcept {
20-
std::copy(sv.begin(), sv.end(), _content.begin());
20+
std::copy(sv.begin(), sv.end(), content_.begin());
2121
}
2222

2323
constexpr operator std::string_view() const noexcept {
24-
return { _content.data(), N };
24+
return { content_.data(), N };
2525
}
2626

2727
private:
28-
std::array<char, N + 1> _content{};
28+
std::array<char, N + 1> content_{};
2929
};
3030

3131
constexpr auto is_pretty(char ch) noexcept {

include/plg/guards.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,35 @@ namespace plg {
99
exception_guard_exceptions() = delete;
1010

1111
constexpr explicit exception_guard_exceptions(Rollback rollback)
12-
: _rollback(std::move(rollback))
13-
, _completed(false) {
12+
: rollback_(std::move(rollback))
13+
, completed_(false) {
1414
}
1515

1616
constexpr exception_guard_exceptions(
1717
exception_guard_exceptions&& other
1818
) noexcept(std::is_nothrow_move_constructible_v<Rollback>)
19-
: _rollback(std::move(other._rollback))
20-
, _completed(other._completed) {
21-
other._completed = true;
19+
: rollback_(std::move(other.rollback_))
20+
, completed_(other.completed_) {
21+
other.completed_ = true;
2222
}
2323

2424
exception_guard_exceptions(const exception_guard_exceptions&) = delete;
2525
exception_guard_exceptions& operator=(const exception_guard_exceptions&) = delete;
2626
exception_guard_exceptions& operator=(exception_guard_exceptions&&) = delete;
2727

2828
constexpr void complete() noexcept {
29-
_completed = true;
29+
completed_ = true;
3030
}
3131

3232
constexpr ~exception_guard_exceptions() {
33-
if (!_completed) {
34-
_rollback();
33+
if (!completed_) {
34+
rollback_();
3535
}
3636
}
3737

3838
private:
39-
PLUGIFY_NO_UNIQUE_ADDRESS Rollback _rollback;
40-
bool _completed;
39+
PLUGIFY_NO_UNIQUE_ADDRESS Rollback rollback_;
40+
bool completed_;
4141
};
4242

4343
template <class Rollback>
@@ -53,24 +53,24 @@ namespace plg {
5353
constexpr exception_guard_noexceptions(
5454
exception_guard_noexceptions&& other
5555
) noexcept(std::is_nothrow_move_constructible_v<Rollback>)
56-
: _completed(other._completed) {
57-
other._completed = true;
56+
: completed_(other.completed_) {
57+
other.completed_ = true;
5858
}
5959

6060
exception_guard_noexceptions(const exception_guard_noexceptions&) = delete;
6161
exception_guard_noexceptions& operator=(const exception_guard_noexceptions&) = delete;
6262
exception_guard_noexceptions& operator=(exception_guard_noexceptions&&) = delete;
6363

6464
constexpr void complete() noexcept {
65-
_completed = true;
65+
completed_ = true;
6666
}
6767

6868
constexpr ~exception_guard_noexceptions() {
69-
PLUGIFY_ASSERT(_completed, "exception_guard not completed with exceptions disabled");
69+
PLUGIFY_ASSERT(completed_, "exception_guard not completed with exceptions disabled");
7070
}
7171

7272
private:
73-
bool _completed = false;
73+
bool completed_ = false;
7474
};
7575

7676
template <class Rollback>
@@ -84,15 +84,15 @@ namespace plg {
8484

8585
template <class Func>
8686
class scope_guard {
87-
PLUGIFY_NO_UNIQUE_ADDRESS Func _func;
87+
PLUGIFY_NO_UNIQUE_ADDRESS Func func_;
8888

8989
public:
9090
constexpr explicit scope_guard(Func func)
91-
: _func(std::move(func)) {
91+
: func_(std::move(func)) {
9292
}
9393

9494
constexpr ~scope_guard() {
95-
_func();
95+
func_();
9696
}
9797

9898
scope_guard(const scope_guard&) = delete;

include/plg/hash.hpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <filesystem>
44
#include <string>
55
#include <vector>
6+
#include <algorithm>
7+
#include <locale>
68

79
#include "plg/string.hpp"
810

@@ -58,11 +60,10 @@ namespace plg {
5860
using is_transparent = void; // Enables heterogeneous lookup
5961

6062
template <typename T>
61-
auto operator()(const T& str_like) const noexcept {
62-
std::string_view str = str_like;
63+
std::size_t operator()(const T& str) const noexcept {
6364
std::size_t hash = active_hash_traits::fnv_basis; // FNV-1a
64-
for (const char& c : str) {
65-
hash ^= static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(c)));
65+
for (const auto& c : str) {
66+
hash ^= static_cast<std::size_t>(std::tolower(c));
6667
hash *= active_hash_traits::fnv_prime;
6768
}
6869
return hash;
@@ -73,21 +74,14 @@ namespace plg {
7374
using is_transparent = void; // Enables heterogeneous lookup
7475

7576
template <typename T1, typename T2>
76-
bool operator()(const T1& lhs_like, const T2& rhs_like) const noexcept {
77-
std::string_view lhs = lhs_like;
78-
std::string_view rhs = rhs_like;
79-
80-
if (lhs.size() != rhs.size()) {
81-
return false;
82-
}
83-
84-
for (size_t i = 0; i < lhs.size(); ++i) {
85-
if (std::tolower(static_cast<unsigned char>(lhs[i]))
86-
!= std::tolower(static_cast<unsigned char>(rhs[i]))) {
87-
return false;
77+
bool operator()(const T1& lhs, const T2& rhs) const noexcept {
78+
return std::lexicographical_compare(
79+
lhs.begin(), lhs.end(),
80+
rhs.begin(), rhs.end(),
81+
[](const auto& ac, const auto& bc) {
82+
return std::tolower(ac) < std::tolower(bc);
8883
}
89-
}
90-
return true;
84+
);
9185
}
9286
};
9387

0 commit comments

Comments
 (0)