@@ -538,10 +518,7 @@ Test 1/1 string literals...OK
In this example the variable c_string_literal has type &const char and
has a terminating null byte.
- See also:
-
+ {#see_also|@embedFile#}
{#header_close#}
{#header_close#}
{#header_open|Assignment#}
@@ -627,12 +604,7 @@ const binary_int = 0b11110000;
integer overflow. Also available are operations such as +% and
-% which are defined to have wrapping arithmetic on all targets.
- See also:
-
+ {#see_also|Integer Overflow|Division by Zero|Wrapping Operations#}
{#header_close#}
{#header_close#}
{#header_open|Floats#}
@@ -680,11 +652,7 @@ $ zig build-exe test.zig --object foo.o
$ ./test
optimized = 1.0e-2
strict = 9.765625e-3
- See also:
-
+ {#see_also|@setFloatMode|Division by Zero#}
{#header_close#}
{#header_open|Operators#}
{#header_open|Table of Operators#}
@@ -1402,11 +1370,7 @@ Test 1/4 iterate over an array...OK
Test 2/4 modify an array...OK
Test 3/4 compile-time array initalization...OK
Test 4/4 array initialization with function calls...OK
- See also:
-
+ {#see_also|for|Slices#}
{#header_close#}
{#header_open|Pointers#}
const assert = @import("std").debug.assert;
@@ -1659,11 +1623,7 @@ Tests failed. Use the following command to reproduce the failure:
Instead, use @bitCast:
@bitCast(u32, f32(12.34))
As an added benefit, the @bitcast version works at compile-time.
- See also:
-
+ {#see_also|Slices|Memory#}
{#header_close#}
{#header_close#}
{#header_open|Slices#}
@@ -1760,12 +1720,7 @@ test "slice widening" {
Test 1/3 using slices for strings...OK
Test 2/3 slice pointer...OK
Test 3/3 slice widening...OK
- See also:
-
+ {#see_also|Pointers|for|Arrays#}
{#header_close#}
{#header_open|struct#}
// Declare a struct.
@@ -1907,11 +1862,7 @@ Test 1/4 dot product...OK
Test 2/4 struct namespaced variable...OK
Test 3/4 field parent pointer...OK
Test 4/4 linked list...OK
- See also:
-
+ {#see_also|comptime|@fieldParentPtr#}
{#header_close#}
{#header_open|enum#}
const assert = @import("std").debug.assert;
@@ -2024,12 +1975,7 @@ Test 5/8 @TagType...OK
Test 6/8 @memberCount...OK
Test 7/8 @memberName...OK
Test 8/8 @tagName...OK
- See also:
-
+ {#see_also|@memberName|@memberCount|@tagName#}
{#header_close#}
{#header_open|union#}
const assert = @import("std").debug.assert;
@@ -2235,13 +2181,7 @@ test "switch inside function" {
Test 1/2 switch simple...OK
Test 2/2 switch enum...OK
Test 3/3 switch inside function...OK
- See also:
-
+ {#see_also|comptime|enum|@compileError|Compile Variables#}
{#header_close#}
{#header_open|while#}
const assert = @import("std").debug.assert;
@@ -2404,14 +2344,7 @@ Test 5/8 while loop continuation expression, more complicated...OK
Test 6/8 while else...OK
Test 7/8 while null capture...OK
Test 8/8 inline while loop...OK
- See also:
-
+ {#see_also|if|Nullables|Errors|comptime|unreachable#}
{#header_close#}
{#header_open|for#}
const assert = @import("std").debug.assert;
@@ -2507,13 +2440,7 @@ Test 1/4 for basics...OK
Test 2/4 for reference...OK
Test 3/4 for else...OK
Test 4/4 inline for loop...OK
- See also:
-
+ {#see_also|while|comptime|Arrays|Slices#}
{#header_close#}
{#header_open|if#}
// If expressions have three uses, corresponding to the three types:
@@ -2628,29 +2555,9 @@ test "if error union" {
Test 1/3 if boolean...OK
Test 2/3 if nullable...OK
Test 3/3 if error union...OK
- See also:
-
+ {#see_also|Nullables|Errors#}
{#header_close#}
- {#header_open|goto#}
- const assert = @import("std").debug.assert;
-
-test "goto" {
- var value = false;
- goto label;
- value = true;
-
-label:
- assert(value == false);
-}
-
- $ zig test goto.zig
-Test 1/1 goto...OK
-
-Note that there are plans to remove goto
-{{deheader_open:fer}}
+ {#header_open|defer#}
const assert = @import("std").debug.assert;
const printf = @import("std").io.stdout.printf;
@@ -2736,10 +2643,7 @@ encountered an error!
end of function
OK
- See also:
-
+ {#see_also|Errors#}
{#header_close#}
{#header_open|unreachable#}
@@ -2811,12 +2715,7 @@ comptime {
test.zig:9:12: error: unreachable code
assert(@typeOf(unreachable) == noreturn);
^
-
See also:
-
+ {#see_also|Zig Test|Build Mode|comptime#}
{#header_close#}
{#header_close#}
{#header_open|noreturn#}
@@ -3142,12 +3041,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -> %u64 {
in other languages.
- See also:
-
+ {#see_also|defer|if|switch#}
{#header_close#}
{#header_open|Nullables#}
@@ -3976,11 +3870,7 @@ comptime {
The result is a target-specific compile time constant. It is guaranteed to be
less than or equal to @sizeOf(T).
- See also:
-
-
+ {#see_also|Alignment#}
{#header_close#}
{#header_open|@cDefine#}
@cDefine(comptime name: []u8, value)
@@ -3999,14 +3889,7 @@ comptime {
Use the void value, like this:
@cDefine("_GNU_SOURCE", {})
- See also:
-
+ {#see_also|Import from C Header File|@cInclude|@cImport|@cUndef|void#}
{#header_close#}
{#header_open|@cImport#}
@cImport(expression) -> (namespace)
@@ -4019,13 +3902,7 @@ comptime {
@cInclude, @cDefine, and @cUndef work
within this expression, appending to a temporary buffer which is then parsed as C code.
- See also:
-
+ {#see_also|Import from C Header File|@cInclude|@cDefine|@cUndef#}
{#header_close#}
{#header_open|@cInclude#}
@cInclude(comptime path: []u8)
@@ -4036,13 +3913,7 @@ comptime {
This appends #include <$path>\n to the c_import
temporary buffer.
- See also:
-
+ {#see_also|Import from C Header File|@cImport|@cDefine|@cUndef#}
{#header_close#}
{#header_open|@cUndef#}
@cUndef(comptime name: []u8)
@@ -4053,13 +3924,7 @@ comptime {
This appends #undef $name to the @cImport
temporary buffer.
- See also:
-
+ {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}
{#header_close#}
{#header_open|@canImplicitCast#}
@canImplicitCast(comptime T: type, value) -> bool
@@ -4091,11 +3956,7 @@ comptime {
AtomicOrder can be found with @import("builtin").AtomicOrder.
@typeOf(ptr).alignment must be >= @sizeOf(T).
- See also:
-
-
+ {#see_also|Compile Variables#}
{#header_close#}
{#header_open|@compileError#}
@compileError(comptime msg: []u8)
@@ -4183,12 +4044,8 @@ test.zig:6:2: error: found compile log statement
@divExact(6, 3) == 2
@divExact(a, b) * b == a
- See also:
-
+ For a function that returns a possible error code, use @import("std").math.divExact.
+ {#see_also|@divTrunc|@divFloor#}
{#header_close#}
{#header_open|@divFloor#}
@divFloor(numerator: T, denominator: T) -> T
@@ -4201,12 +4058,8 @@ test.zig:6:2: error: found compile log statement
@divFloor(-5, 3) == -2
@divFloor(a, b) + @mod(a, b) == a
- See also:
-
+ For a function that returns a possible error code, use @import("std").math.divFloor.
+ {#see_also|@divTrunc|@divExact#}
{#header_close#}
{#header_open|@divTrunc#}
@divTrunc(numerator: T, denominator: T) -> T
@@ -4219,12 +4072,8 @@ test.zig:6:2: error: found compile log statement
@divTrunc(-5, 3) == -1
@divTrunc(a, b) + @rem(a, b) == a
- See also:
-
+ For a function that returns a possible error code, use @import("std").math.divTrunc.
+ {#see_also|@divFloor|@divExact#}
{#header_close#}
{#header_open|@embedFile#}
@embedFile(comptime path: []const u8) -> [X]u8
@@ -4236,10 +4085,7 @@ test.zig:6:2: error: found compile log statement
path is absolute or relative to the current file, just like @import.
- See also:
-
+ {#see_also|@import#}
{#header_close#}
{#header_open|@export#}
@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -> []const u8
@@ -4294,10 +4140,7 @@ test.zig:6:2: error: found compile log statement
AtomicOrder can be found with @import("builtin").AtomicOrder.
- See also:
-
+ {#see_also|Compile Variables#}
{#header_close#}
{#header_open|@fieldParentPtr#}
@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8,
@@ -4338,11 +4181,7 @@ test.zig:6:2: error: found compile log statement
@import("std") - Zig Standard Library
@import("builtin") - Compiler-provided types and variables
- See also:
-
+ {#see_also|Compile Variables|@embedFile#}
{#header_close#}
{#header_open|@inlineCall#}
@inlineCall(function: X, args: ...) -> Y
@@ -4359,10 +4198,7 @@ fn add(a: i32, b: i32) -> i32 { a + b }
Unlike a normal function call, however, @inlineCall guarantees that the call
will be inlined. If the call cannot be inlined, a compile error is emitted.
- See also:
-
+ {#see_also|@noInlineCall#}
{#header_close#}
{#header_open|@intToPtr#}
@intToPtr(comptime DestType: type, int: usize) -> DestType
@@ -4454,11 +4290,8 @@ mem.set(u8, dest, c);
@mod(-5, 3) == 1
@divFloor(a, b) + @mod(a, b) == a
- See also:
-
- - @rem
- @import("std").math.mod
-
+ For a function that returns an error code, see @import("std").math.mod.
+ {#see_also|@rem#}
{#header_close#}
{#header_open|@mulWithOverflow#}
@mulWithOverflow(comptime T: type, a: T, b: T, result: &T) -> bool
@@ -4483,10 +4316,7 @@ fn add(a: i32, b: i32) -> i32 { a + b }
Unlike a normal function call, however, @noInlineCall guarantees that the call
will not be inlined. If the call must be inlined, a compile error is emitted.
- See also:
-
+ {#see_also|@inlineCall#}
{#header_close#}
{#header_open|@offsetOf#}
@offsetOf(comptime T: type, comptime field_name: [] const u8) -> (number literal)
@@ -4529,11 +4359,7 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
From library code, calling the programmer's panic function if they exposed one in the root source file.
When mixing C and Zig code, calling the canonical panic implementation across multiple .o files.
- See also:
-
-
+ {#see_also|Root Source File#}
{#header_close#}
{#header_open|@ptrCast#}
@ptrCast(comptime DestType: type, value: var) -> DestType
@@ -4565,11 +4391,8 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
@rem(-5, 3) == -2
@divTrunc(a, b) + @rem(a, b) == a
- See also:
-
- - @mod
- @import("std").math.rem
-
+ For a function that returns an error code, see @import("std").math.rem.
+ {#see_also|@mod#}
{#header_close#}
{#header_open|@returnAddress#}
@returnAddress()
@@ -4584,7 +4407,6 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
This function is only valid within function scope.
-
{#header_close#}
{#header_open|@setDebugSafety#}
@setDebugSafety(scope, safety_on: bool)
@@ -4623,11 +4445,7 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
$ ./zig build-obj test.zig
(no output because it worked fine)
- See also:
-
-
+ {#see_also|comptime#}
{#header_close#}
{#header_open|@setFloatMode#}
@setFloatMode(scope, mode: @import("builtin").FloatMode)
@@ -4655,21 +4473,14 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
Strict - Floating point operations follow strict IEEE compliance.
- See also:
-
-
+ {#see_also|Floating Point Operations#}
{#header_close#}
{#header_open|@setGlobalLinkage#}
@setGlobalLinkage(global_variable_name, comptime linkage: GlobalLinkage)
GlobalLinkage can be found with @import("builtin").GlobalLinkage.
- See also:
-
+ {#see_also|Compile Variables#}
{#header_close#}
{#header_open|@setGlobalSection#}
@setGlobalSection(global_variable_name, comptime section_name: []const u8) -> bool
@@ -4687,11 +4498,7 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
The type of shift_amt is an unsigned integer with log2(T.bit_count) bits.
This is because shift_amt >= T.bit_count is undefined behavior.
- See also:
-
+ {#see_also|@shrExact|@shlWithOverflow#}
{#header_close#}
{#header_open|@shlWithOverflow#}
@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: &T) -> bool
@@ -4704,11 +4511,7 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
The type of shift_amt is an unsigned integer with log2(T.bit_count) bits.
This is because shift_amt >= T.bit_count is undefined behavior.
- See also:
-
+ {#see_also|@shlExact|@shrExact#}
{#header_close#}
{#header_open|@shrExact#}
@shrExact(value: T, shift_amt: Log2T) -> T
@@ -4720,10 +4523,7 @@ test.zig:5:9: error: expected type '&Derp', found '&Wat'
The type of shift_amt is an unsigned integer with log2(T.bit_count) bits.
This is because shift_amt >= T.bit_count is undefined behavior.
- See also:
-
+ {#see_also|@shlExact|@shlWithOverflow#}
{#header_close#}
{#header_open|@sizeOf#}
@sizeOf(comptime T: type) -> (number literal)
@@ -4863,12 +4663,7 @@ pub fn build(b: &Builder) {
Safety checks enabled
Slow compilation speed
- See also:
-
+ {#see_also|Compile Variables|Zig Build System|Undefined Behavior#}
{#header_close#}
{#header_close#}
{#header_open|Undefined Behavior#}
@@ -5234,10 +5029,7 @@ comptime {
TODO: importance of checking for allocation failure
TODO: mention overcommit and the OOM Killer
TODO: mention recursion
- See also:
-
+ {#see_also|Pointers#}
{#header_close#}
{#header_open|Compile Variables#}
@@ -5406,10 +5198,7 @@ pub const object_format = ObjectFormat.elf;
pub const mode = Mode.ReleaseFast;
pub const link_libs = [][]const u8 {
};
- See also:
-
+ {#see_also|Build Mode#}
{#header_close#}
{#header_open|Root Source File#}
TODO: explain how root source file finds other files
@@ -5456,10 +5245,7 @@ pub const link_libs = [][]const u8 {
c_longdouble
c_void
- See also:
-
+ {#see_also|Primitive Types#}
{#header_close#}
{#header_open|C String Literals#}
extern fn puts(&const u8);
@@ -5472,10 +5258,7 @@ pub fn main() -> %void {
c\\multiline C string literal
);
}
- See also:
-
+ {#see_also|String Literals#}
{#header_close#}
{#header_open|Import from C Header File#}
@@ -5504,14 +5287,7 @@ const c = @cImport({
}
@cInclude("soundio.h");
});
-
See also:
-
+ {#see_also|@cImport|@cInclude|@cDefine|@cUndef|@import#}
{#header_close#}
{#header_open|Mixing Object Files#}
@@ -5571,11 +5347,7 @@ pub fn build(b: &Builder) {
$ zig build
$ ./test
all your base are belong to us
- See also:
-
+ {#see_also|Targets|Zig Build System#}
{#header_close#}
{#header_close#}
{#header_open|Targets#}
diff --git a/std/hash_map.zig b/std/hash_map.zig
index e3c968146e..2cd08d1280 100644
--- a/std/hash_map.zig
+++ b/std/hash_map.zig
@@ -109,6 +109,10 @@ pub fn HashMap(comptime K: type, comptime V: type,
return hm.internalGet(key);
}
+ pub fn contains(hm: &Self, key: K) -> bool {
+ return hm.get(key) != null;
+ }
+
pub fn remove(hm: &Self, key: K) -> ?&Entry {
hm.incrementModificationCount();
const start_index = hm.keyToIndex(key);