diff options
author | Amjad Ben Hedhili <amjadhedhili@outlook.com> | 2023-09-04 22:18:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-04 23:18:58 +0200 |
commit | 8f7aedb3d1941650e6650c07aa4bcf6a7dee0b90 (patch) | |
tree | 3e73c99b08c8d14ce2cad224df8580ab96cb44f1 /lib | |
parent | 3fbb078a3c0f37dc328a1d95e1e2215118481f7b (diff) | |
download | Nim-8f7aedb3d1941650e6650c07aa4bcf6a7dee0b90.tar.gz |
Add `hasDefaultValue` type trait (#22636)
Needed for #21842.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/typetraits.nim | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index 70eb1b81c..384c2dbac 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -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: |