Skip to content

Commit 05cc26e

Browse files
committed
function2.hpp updated
1 parent 60c5508 commit 05cc26e

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

3rdparty/function2/function2.hpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ template <typename Current, typename Next, typename... Rest>
310310
struct overload_impl<Current, Next, Rest...> : Current,
311311
overload_impl<Next, Rest...> {
312312
explicit overload_impl(Current current, Next next, Rest... rest)
313-
: Current(std::move(current)), overload_impl<Next, Rest...>(
314-
std::move(next), std::move(rest)...) {
313+
: Current(std::move(current)),
314+
overload_impl<Next, Rest...>(std::move(next), std::move(rest)...) {
315315
}
316316

317317
using Current::operator();
@@ -338,7 +338,7 @@ namespace type_erasure {
338338
template <typename T, typename = void>
339339
struct address_taker {
340340
template <typename O>
341-
static void* take(O&& obj) {
341+
static auto take(O&& obj) {
342342
return std::addressof(obj);
343343
}
344344
static T& restore(void* ptr) {
@@ -448,6 +448,16 @@ union data_accessor {
448448
}
449449
explicit constexpr data_accessor(void* ptr) noexcept : ptr_(ptr) {
450450
}
451+
explicit constexpr data_accessor(void const* ptr) noexcept
452+
: data_accessor(const_cast<void*>(ptr)) {
453+
}
454+
455+
constexpr void assign_ptr(void* ptr) noexcept {
456+
ptr_ = ptr;
457+
}
458+
constexpr void assign_ptr(void const* ptr) noexcept {
459+
ptr_ = const_cast<void*>(ptr);
460+
}
451461

452462
/// The pointer we use if the object is on the heap
453463
void* ptr_;
@@ -1074,7 +1084,9 @@ struct internal_capacity {
10741084
/// Tag to access the structure in a type-safe way
10751085
data_accessor accessor_;
10761086
/// The internal capacity we use to allocate in-place
1077-
std::aligned_storage_t<Capacity::capacity, Capacity::alignment> capacity_;
1087+
struct alignas(Capacity::alignment) {
1088+
unsigned char data[Capacity::capacity];
1089+
} capacity_;
10781090
} type;
10791091
};
10801092
template <typename Capacity>
@@ -1235,7 +1247,7 @@ class erasure : internal_capacity_holder<typename Config::capacity> {
12351247
template <typename T, typename Allocator = std::allocator<std::decay_t<T>>>
12361248
void assign(std::true_type /*use_bool_op*/, T&& callable,
12371249
Allocator&& allocator_ = {}) {
1238-
if (bool(callable)) {
1250+
if (!!callable) {
12391251
assign(std::false_type{}, std::forward<T>(callable),
12401252
std::forward<Allocator>(allocator_));
12411253
} else {
@@ -1351,12 +1363,12 @@ class erasure<false, Config,
13511363
constexpr void assign(std::false_type /*use_bool_op*/, T&& callable) {
13521364
invoke_table_ = invoke_table_t::template get_invocation_view_table_of<
13531365
std::decay_t<T>>();
1354-
view_.ptr_ =
1355-
address_taker<std::decay_t<T>>::take(std::forward<T>(callable));
1366+
view_.assign_ptr(
1367+
address_taker<std::decay_t<T>>::take(std::forward<T>(callable)));
13561368
}
13571369
template <typename T>
13581370
constexpr void assign(std::true_type /*use_bool_op*/, T&& callable) {
1359-
if (bool(callable)) {
1371+
if (!!callable) {
13601372
assign(std::false_type{}, std::forward<T>(callable));
13611373
} else {
13621374
operator=(nullptr);
@@ -1818,6 +1830,14 @@ constexpr auto overload(T&&... callables) {
18181830
}
18191831
} // namespace fu2
18201832

1833+
namespace std{
1834+
template <typename Config, typename Property, typename Alloc>
1835+
struct uses_allocator<
1836+
::fu2::detail::function<Config, Property>,
1837+
Alloc
1838+
> : std::true_type {};
1839+
} // namespace std
1840+
18211841
#undef FU2_DETAIL_EXPAND_QUALIFIERS
18221842
#undef FU2_DETAIL_EXPAND_QUALIFIERS_NOEXCEPT
18231843
#undef FU2_DETAIL_EXPAND_CV

0 commit comments

Comments
 (0)