Skip to content

Commit 8b9b860

Browse files
committed
fix: update plg includes
1 parent ff6e8bf commit 8b9b860

36 files changed

Lines changed: 508 additions & 56 deletions

include/plg/bitmask.hpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#include <concepts>
4+
#include <type_traits>
5+
6+
namespace plg {
7+
template <typename T>
8+
concept bitmask_enum =
9+
#ifdef __cpp_lib_is_scoped_enum
10+
std::is_scoped_enum_v<T>
11+
#else
12+
std::is_enum_v<T>
13+
#endif
14+
&& requires(T e) {
15+
enable_bitmask_operators(e);
16+
};
17+
18+
template <plg::bitmask_enum T>
19+
class flag {
20+
T val_;
21+
public:
22+
constexpr flag(T val) noexcept : val_(val) {}
23+
constexpr operator T() const noexcept { return val_; }
24+
constexpr explicit operator bool() const noexcept {
25+
using U = std::underlying_type_t<T>;
26+
return static_cast<U>(val_) != 0;
27+
}
28+
};
29+
}
30+
31+
template <plg::bitmask_enum T>
32+
constexpr T operator|(T lhs, T rhs) noexcept {
33+
using U = std::underlying_type_t<T>;
34+
return static_cast<T>(static_cast<U>(lhs) | static_cast<U>(rhs));
35+
}
36+
37+
template <plg::bitmask_enum T>
38+
constexpr plg::flag<T> operator&(T lhs, T rhs) noexcept {
39+
using U = std::underlying_type_t<T>;
40+
return static_cast<T>(static_cast<U>(lhs) & static_cast<U>(rhs));
41+
}
42+
43+
template <plg::bitmask_enum T>
44+
constexpr T operator^(T lhs, T rhs) noexcept {
45+
using U = std::underlying_type_t<T>;
46+
return static_cast<T>(static_cast<U>(lhs) ^ static_cast<U>(rhs));
47+
}
48+
49+
template <plg::bitmask_enum T>
50+
constexpr T operator~(T rhs) noexcept {
51+
using U = std::underlying_type_t<T>;
52+
return static_cast<T>(~static_cast<U>(rhs));
53+
}
54+
55+
template <plg::bitmask_enum T>
56+
constexpr T& operator|=(T& lhs, T rhs) noexcept {
57+
return lhs = lhs | rhs;
58+
}
59+
60+
template <plg::bitmask_enum T>
61+
constexpr T& operator&=(T& lhs, T rhs) noexcept {
62+
return lhs = lhs & rhs;
63+
}
64+
65+
template <plg::bitmask_enum T>
66+
constexpr T& operator^=(T& lhs, T rhs) noexcept {
67+
return lhs = lhs ^ rhs;
68+
}

include/plg/config.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,15 @@ namespace plg {
275275
#if PLUGIFY_COMPILER_GCC || PLUGIFY_COMPILER_CLANG
276276
# define PLUGIFY_RESTRICT __restrict__
277277
# define PLUGIFY_USED __attribute__((used))
278+
# define PLUGIFY_SIGNATURE __PRETTY_FUNCTION__
278279
#elif PLUGIFY_COMPILER_MSVC
279280
# define PLUGIFY_RESTRICT __restrict
280281
# define PLUGIFY_USED __declspec(dllexport)
282+
# define PLUGIFY_SIGNATURE __FUNCSIG__
281283
#else
282284
# define PLUGIFY_RESTRICT
283285
# define PLUGIFY_USED
286+
# define PLUGIFY_SIGNATURE ""
284287
#endif
285288

286289
#if __has_builtin(__builtin_FILE) || (defined(_MSC_VER) && _MSC_VER > 1925)

include/plg/expected.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,4 +1490,4 @@ namespace std {
14901490

14911491
} // namespace std
14921492

1493-
#endif // !PLUGIFY_HAS_STD_EXPECTED
1493+
#endif // !PLUGIFY_HAS_STD_EXPECTED

include/plg/hash.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,33 @@ namespace plg {
113113
return seed;
114114
}
115115

116-
template <typename T1, typename T2>
117116
struct pair_hash {
117+
using is_transparent = void;
118+
119+
template <typename T1, typename T2>
118120
std::size_t operator()(const std::pair<T1, T2>& p) const {
119121
return hash_combine_all(p.first, p.second);
120122
}
121123
};
124+
125+
struct tuple_hash {
126+
using is_transparent = void;
127+
128+
template <typename T>
129+
std::size_t operator()(const T& t) const {
130+
return std::apply([](const auto&... elems) {
131+
return hash_combine_all(elems...);
132+
}, t);
133+
}
134+
};
135+
136+
template <typename T, typename Alloc = std::allocator<T>>
137+
struct vector_hash {
138+
std::size_t operator()(const std::vector<T, Alloc>& v) const {
139+
std::size_t seed = 0;
140+
for (const auto& e : v)
141+
hash_combine(seed, e);
142+
return seed;
143+
}
144+
};
122145
}

include/plg/inplace_vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,4 +773,4 @@ namespace std {
773773
using inplace_vector = plg::inplace_vector<T, N>;
774774
} // namespace std
775775

776-
#endif
776+
#endif

include/plg/source_location.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ namespace plg {
6363
std::string_view function_name_;
6464
std::string_view module_name_;
6565
};
66-
}
66+
}

include/plg/string.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,8 +3959,8 @@ namespace plg {
39593959
constexpr string join(const Range& range, std::string_view separator) {
39603960
string result;
39613961

3962-
auto it = range.cbegin();
3963-
auto end = range.cend();
3962+
auto it = std::cbegin(range);
3963+
auto end = std::cend(range);
39643964

39653965
if (it == end) {
39663966
return result;
@@ -3987,9 +3987,9 @@ namespace plg {
39873987
auto in = std::back_inserter(result);
39883988

39893989
// Second pass: actual formatting
3990-
/*if (it != end)*/ { format_to(in, "{}", *it++); }
3990+
/*if (it != end)*/ { pfl::format_to(in, "{}", *it++); }
39913991
while (it != end) {
3992-
format_to(in, "{}{}", separator, *it++);
3992+
pfl::format_to(in, "{}{}", separator, *it++);
39933993
}
39943994

39953995
return result;
@@ -3999,8 +3999,8 @@ namespace plg {
39993999
constexpr string join(const Range& range, Proj&& proj, std::string_view separator) {
40004000
string result;
40014001

4002-
auto it = range.cbegin();
4003-
auto end = range.cend();
4002+
auto it = std::cbegin(range);
4003+
auto end = std::cend(range);
40044004

40054005
if (it == end) {
40064006
return result;
@@ -4014,7 +4014,7 @@ namespace plg {
40144014
auto&& projected = std::invoke(std::forward<Proj>(proj), *tmp);
40154015
using elem = std::decay_t<decltype(projected)>;
40164016
if constexpr (string_like<elem>) {
4017-
total_size += std::string_view(*projected).size();
4017+
total_size += std::string_view(projected).size();
40184018
} else {
40194019
total_size += pfl::formatted_size("{}", projected);
40204020
}
@@ -4030,11 +4030,11 @@ namespace plg {
40304030
// Second pass: actual formatting
40314031
{
40324032
auto&& projected = std::invoke(std::forward<Proj>(proj), *it++);
4033-
format_to(out, "{}", projected);
4033+
pfl::format_to(out, "{}", projected);
40344034
}
40354035
while (it != end) {
40364036
auto&& projected = std::invoke(std::forward<Proj>(proj), *it++);
4037-
format_to(out, "{}{}", separator, projected);
4037+
pfl::format_to(out, "{}{}", separator, projected);
40384038
}
40394039

40404040
return result;

include/plg/variant.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,4 +1246,4 @@ namespace std {
12461246
#endif // PLUGIFY_VARIANT_NO_STD_HASH
12471247

12481248
#undef PLG_FWD
1249-
#undef PLG_MOV
1249+
#undef PLG_MOV

include/plg/vector.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include "plg/split_buffer.hpp"
2121
#include "plg/uninitialized.hpp"
2222

23+
#ifndef PLUGIFY_VECTOR_NO_STD_HASH
24+
#include "plg/hash.hpp"
25+
#endif
26+
2327
// Just in case, because we can't ignore some warnings from `-Wpedantic` (about zero size arrays and anonymous structs when gnu extensions are disabled) on gcc
2428
#if PLUGIFY_COMPILER_CLANG
2529
# pragma clang system_header
@@ -1573,6 +1577,21 @@ namespace plg {
15731577
} // namespace pmr
15741578
} // namespace plg
15751579

1580+
#ifndef PLUGIFY_VECTOR_NO_STD_HASH
1581+
// hash support
1582+
namespace std {
1583+
template <typename T, typename Alloc>
1584+
struct hash<plg::vector<T, Alloc>> {
1585+
std::size_t operator()(const plg::vector<T, Alloc>& v) const {
1586+
std::size_t seed = 0;
1587+
for (const auto& e : v)
1588+
plg::hash_combine(seed, e);
1589+
return seed;
1590+
}
1591+
};
1592+
}// namespace std
1593+
#endif // PLUGIFY_VECTOR_NO_STD_HASH
1594+
15761595
#ifndef PLUGIFY_VECTOR_NO_STD_UTIL
15771596
#include <optional>
15781597
#include <string_view>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#include <concepts>
4+
#include <type_traits>
5+
6+
namespace plg {
7+
template <typename T>
8+
concept bitmask_enum =
9+
#ifdef __cpp_lib_is_scoped_enum
10+
std::is_scoped_enum_v<T>
11+
#else
12+
std::is_enum_v<T>
13+
#endif
14+
&& requires(T e) {
15+
enable_bitmask_operators(e);
16+
};
17+
18+
template <plg::bitmask_enum T>
19+
class flag {
20+
T val_;
21+
public:
22+
constexpr flag(T val) noexcept : val_(val) {}
23+
constexpr operator T() const noexcept { return val_; }
24+
constexpr explicit operator bool() const noexcept {
25+
using U = std::underlying_type_t<T>;
26+
return static_cast<U>(val_) != 0;
27+
}
28+
};
29+
}
30+
31+
template <plg::bitmask_enum T>
32+
constexpr T operator|(T lhs, T rhs) noexcept {
33+
using U = std::underlying_type_t<T>;
34+
return static_cast<T>(static_cast<U>(lhs) | static_cast<U>(rhs));
35+
}
36+
37+
template <plg::bitmask_enum T>
38+
constexpr plg::flag<T> operator&(T lhs, T rhs) noexcept {
39+
using U = std::underlying_type_t<T>;
40+
return static_cast<T>(static_cast<U>(lhs) & static_cast<U>(rhs));
41+
}
42+
43+
template <plg::bitmask_enum T>
44+
constexpr T operator^(T lhs, T rhs) noexcept {
45+
using U = std::underlying_type_t<T>;
46+
return static_cast<T>(static_cast<U>(lhs) ^ static_cast<U>(rhs));
47+
}
48+
49+
template <plg::bitmask_enum T>
50+
constexpr T operator~(T rhs) noexcept {
51+
using U = std::underlying_type_t<T>;
52+
return static_cast<T>(~static_cast<U>(rhs));
53+
}
54+
55+
template <plg::bitmask_enum T>
56+
constexpr T& operator|=(T& lhs, T rhs) noexcept {
57+
return lhs = lhs | rhs;
58+
}
59+
60+
template <plg::bitmask_enum T>
61+
constexpr T& operator&=(T& lhs, T rhs) noexcept {
62+
return lhs = lhs & rhs;
63+
}
64+
65+
template <plg::bitmask_enum T>
66+
constexpr T& operator^=(T& lhs, T rhs) noexcept {
67+
return lhs = lhs ^ rhs;
68+
}

0 commit comments

Comments
 (0)