-
Notifications
You must be signed in to change notification settings - Fork 0
Add is_convertible_without_narrowing
#54
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
384edff
37bf953
6443dfa
65e4638
9ba01d3
0b16dda
1a0b140
1a35a62
8a4f052
b9c6216
cdec1b1
daab5d1
1380b7e
66ca64b
de99433
c378972
80ad201
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 |
|---|---|---|
|
|
@@ -222,6 +222,43 @@ template<class T> | |
| constexpr bool is_trivially_swappable_v = is_trivially_swappable<T>::value; | ||
|
|
||
|
|
||
| // P0870R7: is_convertible_without_narrowing | ||
| // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p0870r7.html | ||
| template<class From, class To> | ||
| struct is_convertible_without_narrowing | ||
| : std::false_type | ||
| {}; | ||
|
|
||
| template<class From, class To> | ||
| requires | ||
| std::is_convertible_v<From, To> && | ||
| requires { std::type_identity_t<To[]>{std::declval<From>()}; } | ||
| struct is_convertible_without_narrowing<From, To> | ||
| : std::true_type | ||
| {}; | ||
|
|
||
| template<class From, class To> | ||
| inline constexpr bool is_convertible_without_narrowing_v = is_convertible_without_narrowing<From, To>::value; | ||
|
|
||
|
|
||
| // is_assignable_without_narrowing<Dest, Source> | ||
| // | ||
| // True when `Dest = Source` is valid AND does not involve a narrowing conversion. | ||
| // For non-arithmetic Dest types, narrowing is not checked — we trust that the | ||
| // user-defined conversion handles the assignment correctly. | ||
| template<class Dest, class Source> | ||
| struct is_assignable_without_narrowing | ||
| : std::bool_constant< | ||
| std::is_assignable_v<Dest, Source> && | ||
| (!std::is_arithmetic_v<std::remove_reference_t<Dest>> || | ||
| is_convertible_without_narrowing_v<std::remove_cvref_t<Source>, std::remove_reference_t<Dest>>) | ||
| > | ||
| {}; | ||
|
|
||
| template<class Dest, class Source> | ||
| inline constexpr bool is_assignable_without_narrowing_v = is_assignable_without_narrowing<Dest, Source>::value; | ||
|
|
||
|
|
||
| namespace detail { | ||
|
|
||
| template<std::size_t I, class Ti> | ||
|
|
@@ -231,19 +268,12 @@ struct aggregate_initialize_tag | |
| using type = Ti; | ||
| }; | ||
|
|
||
| // This version works better than MSVC's, does not break IntelliSense or ReSharper | ||
| template<std::size_t I, class Ti> | ||
| struct aggregate_initialize_overload | ||
|
yaito3014 marked this conversation as resolved.
Outdated
|
||
| { | ||
| using TiA = Ti[]; | ||
|
|
||
| // https://eel.is/c++draft/dcl.init.general#14 | ||
| // https://eel.is/c++draft/dcl.init.list#3.4 | ||
| // https://eel.is/c++draft/dcl.init.aggr#3 | ||
|
|
||
| template<class T> | ||
| auto operator()(Ti, T&&) -> aggregate_initialize_tag<I, Ti> | ||
| requires requires(T&& t) { { TiA{std::forward<T>(t)} }; } // emulate `Ti x[] = {std::forward<T>(t)};` | ||
| requires is_convertible_without_narrowing_v<T, Ti> | ||
|
Comment on lines
277
to
+279
Contributor
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 think the first parameter
Member
Author
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. No, the For example, constructing |
||
| { | ||
| return {}; // silence MSVC warning | ||
| } | ||
|
|
||
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.
Why? This doesn't make sense at all.
"—" is a very bad sign for vibe coded slop. Please, please double check both the description and code itself.
Do you really think "not is arithmetic" can be the constituent part for being "assignable without narrowing"?
Arithmeric types are just arithmeric types. There should be absolutely no direct relationship to the concept of "assignable", whatever the condition is.
Am I missing something?
I'm really disappointed to see this level of low quality code.
Uh oh!
There was an error while loading. Please reload this page.
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.
As noted in the clarification,
is_assignable_without_narrowingitself was for detecting narrowing conversion, so it was justis_assignablefor non-arithmetic types. The "mistake" was that the trait was used directly in X4 codebase, not the trait definition.I admit that the clarification was missing, but before saying "vibe coded slop" or "low quality code", rethink about it.