The requirement on the Size type passed to *_n algorithms is that it is convertible to an integral type. This means we can't use a variable of type Size directly. Instead we need to convert it to an integral type first. The problem is finding out what integral type to convert it to. __convert_to_integral figures out what integral type to convert it to and performs the conversion, It also promotes the resulting integral type so that it is at least as big as an integer. __convert_to_integral also has a special case for converting enums. This should only work on non-scoped enumerations because it does not apply an explicit conversion from the enum to its underlying type.
Details
- Reviewers
mclow.lists chandlerc - Commits
- rG51544023a955: [libcxx] Properly convert the count arguments to the *_n algorithms before use.
rCXX228704: [libcxx] Properly convert the count arguments to the *_n algorithms before use.
rL228704: [libcxx] Properly convert the count arguments to the *_n algorithms before use.
Diff Detail
- Repository
- rL LLVM
Event Timeline
A few nits; but in general, this looks fine to me
include/algorithm | ||
---|---|---|
1675 ↗ | (On Diff #19435) | I don't think you need a _VSTD:: in front of __convert_to_integral, since it's not a legal identifier, so people can't define their own. |
include/type_traits | ||
3663 ↗ | (On Diff #19435) | Do you need cases for signed char and unsigned char ? |
test/libcxx/type_traits/convert_to_integral.pass.cpp | ||
73 ↗ | (On Diff #19435) | As long as you're modifying this file, please add a newline at the end. |
test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp | ||
21 ↗ | (On Diff #19435) | Rather than having this IntegralConvertible in several source files, should it go into test/support? (suggestion, not requirement) |
Add inline comments.
include/algorithm | ||
---|---|---|
1675 ↗ | (On Diff #19435) | Acknowledged. |
include/type_traits | ||
3663 ↗ | (On Diff #19435) | I thought you might if char was signed char and you wanted to convert unsigned char x = -1; but it actually seems you don't need the char overload at all. I've updated the tests to check the conversion of both the min and max values for each type and I've removed the char overload. |
test/libcxx/type_traits/convert_to_integral.pass.cpp | ||
73 ↗ | (On Diff #19435) | Acknowledged. |
test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp | ||
21 ↗ | (On Diff #19435) | Acknowledged. |