mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 06:45:27 +00:00
add typetraits.pointerBase to return T in ref T|ptr T (#18293)
* add typetraits.deref to return T in ref T|ptr T * deref => refBase * refBase=>pointerBase * [skip ci] address comment
This commit is contained in:
15
changelog.md
15
changelog.md
@@ -113,8 +113,12 @@
|
||||
|
||||
- Make `{.requiresInit.}` pragma to work for `distinct` types.
|
||||
|
||||
- Added a macros `enumLen` for returning the number of items in an enum to the
|
||||
`typetraits.nim` module.
|
||||
- `typetraits`:
|
||||
`distinctBase` now is identity instead of error for non distinct types.
|
||||
Added `enumLen` to return the number of elements in an enum.
|
||||
Added `HoleyEnum` for enums with holes, `OrdinalEnum` for enums without holes.
|
||||
Added `hasClosure`.
|
||||
Added `pointerBase` to return `T` for `ref T | ptr T`.
|
||||
|
||||
- `prelude` now works with the JavaScript target.
|
||||
Added `sequtils` import to `prelude`.
|
||||
@@ -162,8 +166,6 @@
|
||||
Added `symbolName` to return the enum symbol name ignoring the human readable name.
|
||||
Added `symbolRank` to return the index in which an enum member is listed in an enum.
|
||||
|
||||
- Added `typetraits.HoleyEnum` for enums with holes, `OrdinalEnum` for enums without holes.
|
||||
|
||||
- Removed deprecated `iup` module from stdlib, it has already moved to
|
||||
[nimble](https://github.com/nim-lang/iup).
|
||||
|
||||
@@ -293,7 +295,6 @@
|
||||
|
||||
- Added `algorithm.merge`.
|
||||
|
||||
|
||||
- Added `std/jsfetch` module [Fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API) wrapper for JavaScript target.
|
||||
|
||||
- Added `std/jsheaders` module [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) wrapper for JavaScript target.
|
||||
@@ -322,8 +323,6 @@
|
||||
|
||||
- Added `hasDataBuffered` to `asyncnet`.
|
||||
|
||||
- Added `hasClosure` to `std/typetraits`.
|
||||
|
||||
- Added `std/tempfiles`.
|
||||
|
||||
- Added `genasts.genAst` that avoids the problems inherent with `quote do` and can
|
||||
@@ -345,8 +344,6 @@
|
||||
|
||||
- nil dereference is not allowed at compile time. `cast[ptr int](nil)[]` is rejected at compile time.
|
||||
|
||||
- `typetraits.distinctBase` now is identity instead of error for non distinct types.
|
||||
|
||||
- `os.copyFile` is now 2.5x faster on OSX, by using `copyfile` from `copyfile.h`;
|
||||
use `-d:nimLegacyCopyFile` for OSX < 10.5.
|
||||
|
||||
|
||||
@@ -100,6 +100,16 @@ proc isNamedTuple*(T: typedesc): bool {.magic: "TypeTrait".} =
|
||||
doAssert not isNamedTuple((string, int))
|
||||
doAssert isNamedTuple(tuple[name: string, age: int])
|
||||
|
||||
template pointerBase*[T](_: typedesc[ptr T | ref T]): typedesc =
|
||||
## Returns `T` for `ref T | ptr T`.
|
||||
runnableExamples:
|
||||
assert (ref int).pointerBase is int
|
||||
type A = ptr seq[float]
|
||||
assert A.pointerBase is seq[float]
|
||||
assert (ref A).pointerBase is A # not seq[float]
|
||||
assert (var s = "abc"; s[0].addr).typeof.pointerBase is char
|
||||
T
|
||||
|
||||
proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".} =
|
||||
## Returns the base type for distinct types, or the type itself otherwise.
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user