mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-19 01:18:32 +00:00
committed by
GitHub
parent
3fbb078a3c
commit
8f7aedb3d1
@@ -11,7 +11,8 @@
|
||||
|
||||
[//]: # "Additions:"
|
||||
|
||||
- Adds `newStringUninit` to system, which creates a new string of length `len` like `newString` but with uninitialized content.
|
||||
- Added `newStringUninit` to system, which creates a new string of length `len` like `newString` but with uninitialized content.
|
||||
- Added `hasDefaultValue` to `std/typetraits` to check if a type has a valid default value.
|
||||
|
||||
[//]: # "Deprecations:"
|
||||
|
||||
|
||||
@@ -197,6 +197,8 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
|
||||
let complexObj = containsGarbageCollectedRef(t) or
|
||||
hasDestructor(t)
|
||||
result = newIntNodeT(toInt128(ord(not complexObj)), traitCall, c.idgen, c.graph)
|
||||
of "hasDefaultValue":
|
||||
result = newIntNodeT(toInt128(ord(not operand.requiresInit)), traitCall, c.idgen, c.graph)
|
||||
of "isNamedTuple":
|
||||
var operand = operand.skipTypes({tyGenericInst})
|
||||
let cond = operand.kind == tyTuple and operand.n != nil
|
||||
|
||||
@@ -96,6 +96,23 @@ proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".}
|
||||
##
|
||||
## Other languages name a type like these `blob`:idx:.
|
||||
|
||||
proc hasDefaultValue*(t: typedesc): bool {.magic: "TypeTrait".} =
|
||||
## Returns true if `t` has a valid default value.
|
||||
runnableExamples:
|
||||
{.experimental: "strictNotNil".}
|
||||
type
|
||||
NilableObject = ref object
|
||||
a: int
|
||||
Object = NilableObject not nil
|
||||
RequiresInit[T] = object
|
||||
a {.requiresInit.}: T
|
||||
|
||||
assert hasDefaultValue(NilableObject)
|
||||
assert not hasDefaultValue(Object)
|
||||
assert hasDefaultValue(string)
|
||||
assert not hasDefaultValue(var string)
|
||||
assert not hasDefaultValue(RequiresInit[int])
|
||||
|
||||
proc isNamedTuple*(T: typedesc): bool {.magic: "TypeTrait".} =
|
||||
## Returns true for named tuples, false for any other type.
|
||||
runnableExamples:
|
||||
|
||||
Reference in New Issue
Block a user