-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing deduction guides and use type_identity_t
for allocator extended copy/move ctors
#556
base: main
Are you sure you want to change the base?
Changes from 7 commits
93ddae5
4bf1917
2197563
389687b
3bc0f8b
39b2654
5f46074
af5477f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,4 +95,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
#endif //(__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= | ||
// 202002L) | ||
|
||
// | ||
// XYZ_HAS_STD_TYPE_IDENTITY | ||
// The macro is defined when std::type_identity_t<T> is available. | ||
// | ||
|
||
#ifdef XYZ_HAS_STD_TYPE_IDENTITY | ||
#error "XYZ_HAS_STD_TYPE_IDENTITY is already defined" | ||
#endif // XYZ_HAS_STD_TYPE_IDENTITY | ||
|
||
#if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) | ||
#define XYZ_HAS_STD_TYPE_IDENTITY | ||
#endif //(__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= | ||
// 202002L) | ||
Comment on lines
+98
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This macro is set but never used. You use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in tests to disable tests that won't run on older C++ versions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, but it's not used to guard those features in
Theoretically you could support CTAD in C++17 (because CTAD itself was a C++17 feature); but right now you have only your C++14 version (which can't use CTAD) and your C++20 version (which assumes full C++20 support). I'm figuring all this out as I write, so, forgive me if this is all old news. I guess the README already implies that C++17 isn't a supported target. You can probably at least partially ignore this comment, then. I'm still confused why |
||
|
||
#endif // XYZ_FEATURE_CHECK_H |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -182,7 +182,7 @@ class indirect { | |||||||
p_ = construct_from(alloc_, ilist, std::forward<Us>(us)...); | ||||||||
} | ||||||||
|
||||||||
constexpr indirect(std::allocator_arg_t, const A& alloc, | ||||||||
constexpr indirect(std::allocator_arg_t, const std::type_identity_t<A>& alloc, | ||||||||
const indirect& other) | ||||||||
: alloc_(alloc) { | ||||||||
static_assert(std::copy_constructible<T>); | ||||||||
|
@@ -195,7 +195,7 @@ class indirect { | |||||||
} | ||||||||
|
||||||||
constexpr indirect( | ||||||||
std::allocator_arg_t, const A& alloc, | ||||||||
std::allocator_arg_t, const std::type_identity_t<A>& alloc, | ||||||||
indirect&& other) noexcept(allocator_traits::is_always_equal::value) | ||||||||
: p_(nullptr), alloc_(alloc) { | ||||||||
static_assert(std::move_constructible<T>); | ||||||||
|
@@ -465,10 +465,17 @@ concept is_hashable = requires(T t) { std::hash<T>{}(t); }; | |||||||
template <typename Value> | ||||||||
indirect(Value) -> indirect<Value>; | ||||||||
|
||||||||
template <typename Alloc, typename Value> | ||||||||
template <typename Alloc, typename Value, | ||||||||
typename std::enable_if_t<!is_indirect_v<Value>, int> = 0> | ||||||||
Comment on lines
+468
to
+469
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've taken another look and the This issue is possibly related: llvm/llvm-project#57646 Perhaps @Ukilele can comment as he'd had some success implementing deduction guides. |
||||||||
indirect(std::allocator_arg_t, Alloc, Value) -> indirect< | ||||||||
Value, typename std::allocator_traits<Alloc>::template rebind_alloc<Value>>; | ||||||||
|
||||||||
#ifdef XYZ_HAS_EXTENDED_CONSTRUCTOR_TEMPLATE_ARGUMENT_DEDUCTION | ||||||||
template <typename Alloc, typename Value> | ||||||||
indirect(std::allocator_arg_t, std::type_identity_t<Alloc>, | ||||||||
indirect<Value, Alloc>) -> indirect<Value, Alloc>; | ||||||||
#endif // XYZ_HAS_EXTENDED_CONSTRUCTOR_TEMPLATE_ARGUMENT_DEDUCTION | ||||||||
|
||||||||
} // namespace xyz | ||||||||
|
||||||||
template <class T, class Alloc> | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -116,6 +116,15 @@ class direct_control_block final : public control_block<T, A> { | |||||||
|
||||||||
} // namespace detail | ||||||||
|
||||||||
template <class T, class A> | ||||||||
class polymorphic; | ||||||||
|
||||||||
template <class> | ||||||||
inline constexpr bool is_polymorphic_v = false; | ||||||||
|
||||||||
template <class T, class A> | ||||||||
inline constexpr bool is_polymorphic_v<polymorphic<T, A>> = true; | ||||||||
|
||||||||
template <class T, class A = std::allocator<T>> | ||||||||
class polymorphic { | ||||||||
using cblock_t = detail::control_block<T, A>; | ||||||||
|
@@ -241,7 +250,8 @@ class polymorphic { | |||||||
cb_ = create_control_block<U>(ilist, std::forward<Ts>(ts)...); | ||||||||
} | ||||||||
|
||||||||
constexpr polymorphic(std::allocator_arg_t, const A& alloc, | ||||||||
constexpr polymorphic(std::allocator_arg_t, | ||||||||
const std::type_identity_t<A>& alloc, | ||||||||
const polymorphic& other) | ||||||||
: alloc_(alloc) { | ||||||||
if (!other.valueless_after_move()) { | ||||||||
|
@@ -252,7 +262,7 @@ class polymorphic { | |||||||
} | ||||||||
|
||||||||
constexpr polymorphic( | ||||||||
std::allocator_arg_t, const A& alloc, | ||||||||
std::allocator_arg_t, const std::type_identity_t<A>& alloc, | ||||||||
polymorphic&& other) noexcept(allocator_traits::is_always_equal::value) | ||||||||
: alloc_(alloc) { | ||||||||
if constexpr (allocator_traits::is_always_equal::value) { | ||||||||
|
@@ -404,7 +414,19 @@ class polymorphic { | |||||||
} | ||||||||
} | ||||||||
}; | ||||||||
|
||||||||
#ifdef XYZ_HAS_EXTENDED_CONSTRUCTOR_TEMPLATE_ARGUMENT_DEDUCTION | ||||||||
template <typename Value> | ||||||||
polymorphic(Value) -> polymorphic<Value>; | ||||||||
|
||||||||
template <typename Alloc, typename Value, | ||||||||
typename std::enable_if_t<!is_polymorphic_v<Value>, int> = 0> | ||||||||
Comment on lines
+421
to
+422
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same here: the deduction guide on line 427 is more specific so the And a big bonus here: you can get rid of your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, |
||||||||
polymorphic(std::allocator_arg_t, Alloc, Value) -> polymorphic< | ||||||||
Value, typename std::allocator_traits<Alloc>::template rebind_alloc<Value>>; | ||||||||
|
||||||||
template <typename Alloc, typename Value> | ||||||||
polymorphic(std::allocator_arg_t, std::type_identity_t<Alloc>, | ||||||||
polymorphic<Value, Alloc>) -> polymorphic<Value, Alloc>; | ||||||||
#endif // XYZ_HAS_EXTENDED_CONSTRUCTOR_TEMPLATE_ARGUMENT_DEDUCTION | ||||||||
} // namespace xyz | ||||||||
|
||||||||
#endif // XYZ_POLYMORPHIC_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of
XYZ_HAS_EXTENDED_CONSTRUCTOR_TEMPLATE_ARGUMENT_DEDUCTION
? Does it cause problems for some compilers?I would expect that all compilers should be able to support these deduction guides, and so you wouldn't need to hide them under a build flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep extended features as explicit opt-in for now.
We check
XYZ_HAS_EXTENDED_CONSTRUCTOR_TEMPLATE_ARGUMENT_DEDUCTION
in tests to ensure that appropriate tests are only run when extended features are enabled.