aboutsummaryrefslogtreecommitdiff
path: root/lib/std/mem.zig
AgeCommit message (Collapse)Author
2022-08-24docs: remove confusion about align[For|Back]wardJonas Gollenz
2022-08-22stage2+stage1: remove type parameter from bit builtinsVeikka Tuominen
Closes #12529 Closes #12511 Closes #6835
2022-08-05std.mem.zeroes: Zero sized structs with uninitialized members (#12246)N00byEdge
`std.mem.zeroes(struct{handle: void})` Failed with the following error before: ``` /nix/store/l6v4359wc9xrxxmvvp3rynsb5s3d78xf-zig-0.9.1/lib/zig/std/mem.zig:270:42: error: missing field: 'handle' if (@sizeOf(T) == 0) return T{}; ^ ```
2022-07-26std.mem: add `reset` to `SplitBackwardsIterator` and `SplitIterator`r00ster
2022-07-25std.mem: add `first` method to `SplitIterator` and `SplitBackwardsIterator`r00ster
2022-07-12std: update test cases to reflect new packed struct semanticsAndrew Kelley
2022-07-03std: disable tests regressed from LLVM 14Andrew Kelley
2022-06-29mem: add splitBackwards (#11908)Motiejus Jakštys
* mem: refactor tests of split() - add a few cases for .rest() - use expectEqualSlices() * mem: add splitBackwards Over the last couple of weeks weeks I needed to iterate over a collection backwards at least twice. Do we want to have this in stdlib? If yes, click "Merge" and start using today! Free shipping and returns (before 1.0). Why is this useful? ------------------- I need this for building an error wrapper: errors are added in the wrapper from "lowest" level to "highest" level, and then printed in reverse order. Imagine `UpdateUsers` call, which needs to return `error.InvalidInput` and a wrappable error context. In Go we would add a context to the error when returning it: // if update_user fails, add context on which user we are operating if err := update_user(user); err != nil { return fmt.Errorf("user id=%d: %w", user.id, err) } Since Zig cannot pass anything else than u16 with an error (#2647), I will pass a `err_ctx: *Err`, to the callers, where they can, besides returning an error, augment it with auxiliary data. `Err` is a preallocated array that can add zero-byte-separated strings. For a concrete example, imagine such a call graph: update_user(User, *Err) error{InvalidInput}!<...> validate_user([]const u8, *Err) error{InvalidInput}!<...> Where `validate_user` would like, besides only the error, signal the invalid field. And `update_user`, besides the error, would signal the offending user id. We also don't want the low-level functions to know in which context they are operating to construct a meaningful error message: if validation fails, they append their "context" to the buffer. To translate/augment the Go example above: pub fn validate_user(err_ctx: *Err, user: User) error{InvalidInput}!void { const name = user.name; if (!ascii.isAlpha(name)) { err_ctx.print("name '{s}' must be ascii-letters only", .{name}); return error.InvalidInput; } <...> } // update_user validates each user and does something with it. pub fn update_user(err_ctx: *Err, user: User) error{InvalidInput}!void { // validate the user before updating it validate_user(user) catch { err_ctx.print("user id={d}", .{user.id}); return error.InvalidInput; }; <...> } Then the top-level function (in my case, CLI) will read the buffer backwards (splitting on `"\x00"`) and print: user id=123: name 'Žvangalas' must be ascii-letters only To read that buffer backwards, dear readers of this commit message, I need `mem.splitBackwards`.
2022-06-28std.mem: add peek() to TokenIterator(T)Ben Fiedler
2022-06-18value: handle slices in canMutateComptimeVarStateVeikka Tuominen
2022-06-12Merge pull request #11837 from Vexu/stage2Andrew Kelley
Fix (nearly) all stage2 crashes when testing stdlib
2022-06-12std.mem.zeroes: remove call to std.metaAndrew Kelley
everybody is so horny for std.meta
2022-06-12std: disable failing tests, add zig2 build test-std to CIVeikka Tuominen
2022-05-13target: Rename sparcv9 -> sparc64Koakuma
Rename all references of sparcv9 to sparc64, to make Zig align more with other projects. Also, added new function to convert glibc arch name to Zig arch name, since it refers to the architecture as sparcv9. This is based on the suggestion by @kubkon in PR 11847. (https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-04-21std.mem: add concatWithSentinelYusuf Bham
2022-03-28std.mem.zeroInit: Fix behaviour with empty initialiserominitay
2022-03-09std.mem: remove redundant namespaces in test namesAndrew Kelley
related: #7923
2022-03-08deprecated TypeInfo in favor of TypeJonathan Marler
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-02-07std: Allow `mem.zeroes` to work at comptime with extern unionEvan Haas
Fixes #10797
2022-02-01stage1: avoid anytype fields for type infoAndrew Kelley
prerequisite for #10705
2022-01-29Merge pull request #9915 from zzyxyzz/indexOfMinMaxVeikka Tuominen
std.mem: add indexOfMin and indexOfMax
2022-01-28Rename mem.bswapAllFields to byteSwapAllFieldsJohn Schmidt
To match the renaming of `@bswap` to `@byteSwap` in https://github.com/ziglang/zig/commit/1fdb24827fb51351d5e31103069619668fae31c4.
2022-01-27Add std.mem.minMax() and std.mem.IndexOfMinMax()Mikhail Popov
For finding the minimum and maximum values (and indices) in a slice in a single pass.
2022-01-27std.mem: Add functions to find the index of the mimimum/maximum value in a ↵Mikhail Popov
slice.
2022-01-26Update the documentation for std.mem.sliceTo for readabilityJosh Hannaford
2021-12-27std: Skip `comptime` struct fields in `mem.zeroes()` (#10406)Ali Chraghi
closes #9934
2021-12-19stage1, stage2: rename c_void to anyopaque (#10316)Isaac Freund
zig fmt now replaces c_void with anyopaque to make updating code easy.
2021-11-30allocgate: change resize to return optional instead of errorLee Cannon
2021-11-30allocgate: split free out from resizeLee Cannon
2021-11-30allocgate: utilize a *const vtable fieldLee Cannon
2021-11-30allocgate: fix failing testsLee Cannon
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: dont use a dummy temporary for stateless allocatorsLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-25std.mem.indexOfPos should return start_index when needle length is zero (#10220)Fabio Arnold
Closes #10216
2021-11-21Fix type error for u8 in writeIntSliceTrioct
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-09-22FIX resize() for non u8 element types. (#9806)Coleman Broaddus
2021-09-20Address Spaces: Pointer and function info in @TypeRobin Voetter
2021-08-29zig fmt: respect trailing commas in inline assemblyjdmichaud
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-11Update mem.split/mem.tokenize doc commentsRyan Liptak
Follow up to #9531
2021-08-06Make mem.split and mem.tokenize generic instead of assuming u8Ryan Liptak
This allows these functions to work on slices of u16, etc
2021-07-02stage2: improve AstGen FileNotFound error messageAndrew Kelley
Partially addresses #9203. It fixes the first case, but not the second one mentioned in the issue.
2021-06-25Add fat/universal dylib support to zig ldTom Maenan Read Cutting
With this change zig ld can link with dynamic libraries contained within a fat/universal file that had multiple seperate binaries embedded within it for multi-arch support (in macOS). Whilst zig can still only create single-architecture executables - the ability to link with fat libraries is useful for cases where they are the easiest (or only) option to link against.
2021-06-21fix code broken from previous commitJacob G-W
2021-06-06fix doc comments copy paste typoAndrew Kelley
2021-06-06std: Add helpers to safely align pointersLemonBoy
Add two helpers to ensure people won't ignore some edge cases such as pointers overflowing the address space. Also fix #8924 to some degree, the amount of unchecked alignForward is still scary.
2021-06-01os/bits: remove duplicate `sockaddr_storage` for dragonflyKenta Iwasaki