Skip to content

Commit f428f1e

Browse files
committed
any: cleanup
1 parent 311db0b commit f428f1e

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

‎src/entt/core/any.hpp‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
126126
}
127127
}
128128

129-
template<typename Type, typename... Args>
130-
decltype(auto) initialize([[maybe_unused]] Args &&...args) {
129+
template<typename Type>
130+
decltype(auto) initialize([[maybe_unused]] auto &&...args) {
131131
using plain_type = stl::remove_cvref_t<Type>;
132132

133133
vtable = basic_vtable<plain_type>;
@@ -141,7 +141,7 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
141141
deleter = nullptr;
142142
using non_reference_type = stl::remove_reference_t<Type>;
143143
mode = stl::is_const_v<non_reference_type> ? any_policy::cref : any_policy::ref;
144-
static_assert((stl::is_lvalue_reference_v<Args> && ...) && (sizeof...(Args) == 1u), "Invalid arguments");
144+
static_assert((stl::is_lvalue_reference_v<decltype(args)> && ...) && (sizeof...(args) == 1u), "Invalid arguments");
145145
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
146146
this->instance = (stl::addressof(args), ...);
147147
return *static_cast<non_reference_type *>(const_cast<constness_as_t<void, non_reference_type> *>(this->instance));
@@ -154,23 +154,23 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
154154

155155
mode = any_policy::embedded;
156156

157-
if constexpr(stl::is_aggregate_v<plain_type> && (sizeof...(Args) != 0u || !stl::is_default_constructible_v<plain_type>)) {
158-
return *::new(&this->buffer) plain_type{stl::forward<Args>(args)...};
157+
if constexpr(stl::is_aggregate_v<plain_type> && (sizeof...(args) != 0u || !stl::is_default_constructible_v<plain_type>)) {
158+
return *::new(&this->buffer) plain_type{stl::forward<decltype(args)>(args)...};
159159
} else {
160160
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
161-
return *::new(&this->buffer) plain_type(stl::forward<Args>(args)...);
161+
return *::new(&this->buffer) plain_type(stl::forward<decltype(args)>(args)...);
162162
}
163163
} else {
164164
deleter = &basic_deleter<plain_type>;
165165
mode = any_policy::dynamic;
166166

167-
if constexpr(stl::is_aggregate_v<plain_type> && (sizeof...(Args) != 0u || !stl::is_default_constructible_v<plain_type>)) {
168-
this->instance = new plain_type{stl::forward<Args>(args)...};
167+
if constexpr(stl::is_aggregate_v<plain_type> && (sizeof...(args) != 0u || !stl::is_default_constructible_v<plain_type>)) {
168+
this->instance = new plain_type{stl::forward<decltype(args)>(args)...};
169169
} else if constexpr(stl::is_array_v<plain_type>) {
170-
static_assert(sizeof...(Args) == 0u, "Invalid arguments");
170+
static_assert(sizeof...(args) == 0u, "Invalid arguments");
171171
this->instance = new plain_type[stl::extent_v<plain_type>]();
172172
} else {
173-
this->instance = new plain_type(stl::forward<Args>(args)...);
173+
this->instance = new plain_type(stl::forward<decltype(args)>(args)...);
174174
}
175175

176176
return *static_cast<plain_type *>(const_cast<void *>(this->instance));
@@ -196,13 +196,12 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
196196
/**
197197
* @brief Constructs a wrapper by directly initializing the new object.
198198
* @tparam Type Type of object to use to initialize the wrapper.
199-
* @tparam Args Types of arguments to use to construct the new instance.
200199
* @param args Parameters to use to construct the instance.
201200
*/
202-
template<typename Type, typename... Args>
203-
explicit basic_any(stl::in_place_type_t<Type>, Args &&...args)
201+
template<typename Type>
202+
explicit basic_any(stl::in_place_type_t<Type>, auto &&...args)
204203
: base_type{} {
205-
initialize<Type>(stl::forward<Args>(args)...);
204+
initialize<Type>(stl::forward<decltype(args)>(args)...);
206205
}
207206

208207
/**
@@ -423,14 +422,13 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
423422
/**
424423
* @brief Replaces the contained object by creating a new instance directly.
425424
* @tparam Type Type of object to use to initialize the wrapper.
426-
* @tparam Args Types of arguments to use to construct the new instance.
427425
* @param args Parameters to use to construct the instance.
428426
* @return A reference to the newly created object, if any.
429427
*/
430-
template<typename Type, typename... Args>
431-
decltype(auto) emplace(Args &&...args) {
428+
template<typename Type>
429+
decltype(auto) emplace(auto &&...args) {
432430
invoke_deleter_if_exists();
433-
return initialize<Type>(stl::forward<Args>(args)...);
431+
return initialize<Type>(stl::forward<decltype(args)>(args)...);
434432
}
435433

436434
/**
@@ -589,13 +587,12 @@ template<typename Type, stl::size_t Len, stl::size_t Align>
589587
* @tparam Type Type of object to use to initialize the wrapper.
590588
* @tparam Len Size of the buffer reserved for the small buffer optimization.
591589
* @tparam Align Optional alignment requirement.
592-
* @tparam Args Types of arguments to use to construct the new instance.
593590
* @param args Parameters to use to construct the instance.
594591
* @return A properly initialized wrapper for an object of the given type.
595592
*/
596-
template<typename Type, stl::size_t Len = basic_any<>::length, stl::size_t Align = basic_any<Len>::alignment, typename... Args>
597-
[[nodiscard]] basic_any<Len, Align> make_any(Args &&...args) {
598-
return basic_any<Len, Align>{stl::in_place_type<Type>, stl::forward<Args>(args)...};
593+
template<typename Type, stl::size_t Len = basic_any<>::length, stl::size_t Align = basic_any<Len>::alignment>
594+
[[nodiscard]] basic_any<Len, Align> make_any(auto &&...args) {
595+
return basic_any<Len, Align>{stl::in_place_type<Type>, stl::forward<decltype(args)>(args)...};
599596
}
600597

601598
/**

0 commit comments

Comments
 (0)