From 99bc53f5e819c2d2d49f2a56c488898085be3982 Mon Sep 17 00:00:00 2001
From: Cuong Manh Le len
and may change during execution. Elements may be added during execution
using assignments and retrieved with
index expressions; they may be removed with the
-delete
built-in function.
+delete
and
+clear
built-in function.
A new, empty map value is made using the built-in
function make
,
@@ -2316,7 +2318,7 @@ Zero value:
nil
Functions:
- append cap close complex copy delete imag len
+ append cap clear close complex copy delete imag len
make new panic print println real recover
@@ -7181,6 +7183,36 @@ so they can only appear in call expressions;
they cannot be used as function values.
+The built-in function clear
takes an argument of map,
+slice, or type parameter type,
+and deletes or zeroes out all elements.
+
+Call Argument type Result
+
+clear(m) map[K]T deletes all entries, resulting in an
+ empty map (len(m) == 0)
+
+clear(s) []T sets all elements up to the length of
+ s
to the zero value of T
+
+clear(t) type parameter see below
+
+
+
+If the argument type is a type parameter,
+all types in its type set must be maps or slices, and clear
+performs the operation corresponding to the actual type argument.
+
+If the map or slice is nil
, clear
is a no-op.
+