Repository navigation
Closed
Description
This feature was used for these things:
- For structs which are created with comptime parameters to reference the type:
pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
return struct {
const Self = this;
...- For builtin functions to refer to a "scope" type:
[nix-shell:~/downloads/zig/build]$ grep -RI setFloatMode ../std/
../std/math/pow.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/expm1.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/expm1.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/tan.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/sinh.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/ln.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/ln.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/complex/exp.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/floor.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/floor.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/exp2.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/exp2.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/exp.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/exp.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/cos.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/round.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/round.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/sin.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
../std/math/ceil.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/math/ceil.zig: @setFloatMode(this, builtin.FloatMode.Strict);
../std/fmt/errol/index.zig: @setFloatMode(this, @import("builtin").FloatMode.Strict);
Here's my proposal to replace these uses:
- Provide builtin function for getting the current type:
@ThisType()- searches up in scope until it finds a struct, union, enum, or error, and returns that type. - Remove the scope parameter from the builtin functions such as
@setFloatMode. We were always passingthisanyway.
Reacted by Stevie Hryciw, Matthew D. Steele and Shawn Landden
Activity
thejoshwolfe commentedon Jul 24, 2018
I use
thisto refer to the top level scope also. Would@ThisType()give me the global namespace outside of any other type?andrewrk commentedon Jul 24, 2018
With #1047 it certainly would. Probably even without that proposal, it would refer to the namespace as you said.
remove the scope parameter of setFloatMode