table.mgetOrPut without default val (#22994)

RFC: https://github.com/nim-lang/RFCs/issues/539

- ~~mgetOrPutDefaultImpl template into `tableimpl.nim` to avoid macros~~
- mgetOrPut for `Table`, `TableRef`, `OrderedTable`, `OrderedTableRef`
- `tests/stdlib/tmget.nim` tests update

---------

Co-authored-by: inv2004 <>
This commit is contained in:
inv2004
2023-11-30 11:00:33 +01:00
committed by GitHub
parent beeacc86ff
commit 0f7ebb490c
3 changed files with 81 additions and 4 deletions

View File

@@ -3,15 +3,19 @@ discard """
output: '''Can't access 6
10
11
2
Can't access 6
10
11
2
Can't access 6
10
11
2
Can't access 6
10
11
2
0
10
11
@@ -41,6 +45,9 @@ block:
x[5] += 1
var c = x[5]
echo c
x.mgetOrPut(7).inc
x.mgetOrPut(7).inc
echo x[7]
block:
var x = newTable[int, int]()
@@ -53,6 +60,9 @@ block:
x[5] += 1
var c = x[5]
echo c
x.mgetOrPut(7).inc
x.mgetOrPut(7).inc
echo x[7]
block:
var x = initOrderedTable[int, int]()
@@ -65,6 +75,9 @@ block:
x[5] += 1
var c = x[5]
echo c
x.mgetOrPut(7).inc
x.mgetOrPut(7).inc
echo x[7]
block:
var x = newOrderedTable[int, int]()
@@ -77,6 +90,9 @@ block:
x[5] += 1
var c = x[5]
echo c
x.mgetOrPut(7).inc
x.mgetOrPut(7).inc
echo x[7]
block:
var x = initCountTable[int]()