-
Notifications
You must be signed in to change notification settings - Fork 10
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
Enforce user literals parsing #50
base: main
Are you sure you want to change the base?
Conversation
UDLs will never receive the negative sign? Unary minus is an operator, not part of a literal. https://godbolt.org/z/M1hneGfj7 |
See the point. My understanding wasn't correct. Hence, think it can be split in following steps:
Am I missing something? |
I think you can just remove the negative decimal integer concept and it's fine. The library should already handle unary minus. |
requires std::unsigned_integral<T>; | ||
} && (is_0_v<Char0> && is_x_v<Char1> && (is_hex_digit_v<Chars> && ...)); | ||
} // namespace safe::detail |
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.
suggestion: You have a mix of constexpr bool
s, bool_constant
types, and concepts here. I would make them all concepts and express the subsumption relationships clearly.
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.
Start getting the idea of how to better express concepts. requires
would normally be used when we want to handle a value of certain type, like here
include/safe/detail/concepts.hpp
Outdated
template <typename T, char... Chars> | ||
concept positive_decimal_integer = requires { requires std::integral<T>; } && | ||
(is_decimal_digit_v<Chars> && ...); |
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.
issue: Rather than using a nested concept, just put the concept itself. So:
template <typename T, char... Chars>
concept positive_decimal_integer = std::integral<T> &&
(is_decimal_digit_v<Chars> && ...);
That will enable the compiler to see subsumption, which means easier overload sets.
include/safe/detail/concepts.hpp
Outdated
|
||
template <char Char> | ||
constexpr bool is_decimal_digit_v = Char - '0' >= 0 && Char - '0' <= 9; |
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.
suggestion: Why not Char >= '0' and Char <= '9'
? Is the subtraction/integral promotion giving us anything?
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.
Agree. No benefit from subtraction. Like to how the suggestion reads
Gotcha. Haven't seen anything in dsl/minus.hpp, but found later in var. |
Restructuring the PR. |
50e8eab
to
684a8ac
Compare
ab702fe
to
2b01d0d
Compare
@elbeno are there any specific requirements for clang-format? Is the style based on LLVM or Google? |
0cfb20f
to
3ee899f
Compare
Closes #11
Current implementation contains a 🐛 bug. Compilation will not fail for invalid values captured by user literals. Such weakness puts in danger the whole purpose of the safety library. Stronger user literals parsing is needed.
This PR adds strong support for positive decimal and hexadecimal numbers along with negative decimals. The support is provided through creation of three concepts: positive_decimal_integer, negative_decimal_integer, and positive_hex_integer. These concepts match provided values with intended types and dispatch appropriate parsing function. So, additional safety is provided.