-
-
Notifications
You must be signed in to change notification settings - Fork 753
[docs] Improve docs for std.conv.to #4900
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68c14cd
Improve docs for std.conv.to
ntrel 691eb76
Document basic function signatures for `to`
ntrel 7962a36
Simplify `to` function constraints
ntrel 4074790
Move manual radix signatures to relevant places
ntrel a469694
Undocument `to` overloads to get other changes merged
ntrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,8 +176,9 @@ class ConvOverflowException : ConvException | |
| } | ||
|
|
||
| /** | ||
| The `to` template converts a value from one type _to another. | ||
| The source type is deduced and the target type must be specified, for example the | ||
| $(D_CODE T $(DDOC_PSYMBOL _to)$(DDOC_TEMPLATE_PARAM_LIST (S))(S value);) | ||
| Converts a value from one type _to type `T`. | ||
| The source type `S` is deduced and the target type must be specified, for example the | ||
| expression `to!int(42.0)` converts the number 42 from | ||
| `double` _to `int`. The conversion is "safe", i.e., | ||
| it checks for overflow; `to!int(4.2e10)` would throw the | ||
|
|
@@ -240,7 +241,7 @@ template to(T) | |
| * Conversions from floating-point types _to integral types allow loss of | ||
| * precision (the fractional part of a floating-point number). The | ||
| * conversion is truncating towards zero, the same way a cast would | ||
| * truncate. (_To round a floating point value when casting _to an | ||
| * truncate. (To round a floating point value when casting _to an | ||
| * integral, use `roundTo`.) | ||
| */ | ||
| @safe pure unittest | ||
|
|
@@ -260,11 +261,12 @@ template to(T) | |
|
|
||
| /** | ||
| * When converting strings _to numeric types, note that the D hexadecimal and binary | ||
| * literals are not handled. Neither the prefixes that indicate the base, nor the | ||
| * literals are $(B not) handled. Neither the prefixes that indicate the base, nor the | ||
| * horizontal bar used _to separate groups of digits are recognized. This also | ||
| * applies to the suffixes that indicate the type. | ||
| * applies _to the suffixes that indicate the type. | ||
| * | ||
| * _To work around this, you can specify a radix for conversions involving numbers. | ||
| * To work around this, you can specify a radix for conversions involving numbers: | ||
| * $(D_CODE T $(DDOC_PSYMBOL _to)$(DDOC_TEMPLATE_PARAM_LIST (S))(S value, uint radix);) | ||
|
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. |
||
| */ | ||
| @safe pure unittest | ||
| { | ||
|
|
@@ -387,13 +389,14 @@ template to(T) | |
| * $(LI $(D char), $(D wchar), $(D dchar) _to a string type.) | ||
| * $(LI Unsigned or signed integers _to strings. | ||
| * $(DL $(DT [special case]) | ||
| * $(DD Convert integral value _to string in $(D_PARAM radix) radix. | ||
| * radix must be a value from 2 to 36. | ||
| * value is treated as a signed value only if radix is 10. | ||
| * The characters A through Z are used to represent values 10 through 36 | ||
| * and their case is determined by the $(D_PARAM letterCase) parameter.))) | ||
| * $(D_CODE T $(DDOC_PSYMBOL _to)$(DDOC_TEMPLATE_PARAM_LIST (S))(S value, uint radix, LetterCase lc = LetterCase.upper);) | ||
| * $(DD Converts an integral value _to a string using a radix. | ||
| * $(D_PARAM radix) must be a value from 2 _to 36. | ||
| * $(D_PARAM value) is treated as a signed value only if $(D_PARAM radix) is 10. | ||
| * The characters A through Z are used _to represent values 10 through 36. | ||
| * $(D_PARAM letterCase) is the case _to use for non-decimal output characters.))) | ||
|
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. |
||
| * $(LI All floating point types _to all string types.) | ||
| * $(LI Pointer to string conversions prints the pointer as a $(D size_t) value. | ||
| * $(LI Pointer _to string conversions prints the pointer as a $(D size_t) value. | ||
| * If pointer is $(D char*), treat it as C-style strings. | ||
| * In that case, this function is $(D @system).)) | ||
| */ | ||
|
|
@@ -6251,7 +6254,7 @@ private auto hexStrImpl(String)(scope String hexData) | |
|
|
||
|
|
||
| /** | ||
| * Convert integer to a range of characters. | ||
| * Converts integer to a range of characters. | ||
| * Intended to be lightweight and fast. | ||
| * | ||
| * Params: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



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.
There's any precedent for this, is there?