# Looping on \[\]MyType backed by \[\]MySuperType

**URL:** <https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023>\
**Category:** Help\
**Tags:** language\
**Created:** [October 18, 2026, 5:52pm UTC](https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023 "2026-10-18T17:52:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nour](https://ziggit.dev/user_avatar/ziggit.dev/nour/32/10166_2.png) [@nour](https://ziggit.dev/u/nour)\
**Post date:** [October 18, 2026, 5:52pm UTC](https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023/1 "2026-10-18T17:52:38Z")

</div>

Hello,

In a painting software defining `TabletPoint` which contains `.position` (a vector field).  
I have `[]TabletPoint`.

I have a `transform` library which acts on vectors and doesn’t bother with `TabletPoint`. It’s not coupled.

I am writing `transform.alignPoints([]@Vector(2, f32), other_params...)` which only needs to act on the `.position` field by reference.  
However, that would mean allocating that list of references.

I wonder if there is a way to go for accessing the `.position` field of my existing `[]TabletPoint`… yet without having to import `TabletPoint`…

Even if I abstract it as an `anytype` or so, I would still enforce it has a field that is named `.position` I guess? That would feel half-way done…

Separating fields in a `MultiArrayList` would be a cumbersome solution, as the fields of the `TabletPoint` are all unique to each point.

---

<div class="post-metadata">

**Author:** ![WiserOrb](https://ziggit.dev/user_avatar/ziggit.dev/wiserorb/32/3853_2.png) [@WiserOrb](https://ziggit.dev/u/WiserOrb)\
**Post date:** [October 18, 2026, 6:14pm UTC](https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023/2 "2026-10-18T18:14:43Z")

</div>

I think there is not a standard way to do it. However you can take inspiration from Fortran arrays.

A “slice” in fortran is defined by base pointer, stride and length. (It’s a bit more complicated but that’s the gist of it.)

You could implement a similar structure + getters and initializers to make the function work with different strides.

---

<div class="post-metadata">

**Author:** ![biom4st3r](https://ziggit.dev/user_avatar/ziggit.dev/biom4st3r/32/4342_2.png) [@biom4st3r](https://ziggit.dev/u/biom4st3r)\
**Post date:** [October 18, 2026, 6:29pm UTC](https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023/3 "2026-10-18T18:29:47Z")

</div>

(post deleted by author)

---

<div class="post-metadata">

**Author:** ![WiserOrb](https://ziggit.dev/user_avatar/ziggit.dev/wiserorb/32/3853_2.png) [@WiserOrb](https://ziggit.dev/u/WiserOrb)\
**Post date:** [October 18, 2026, 6:39pm UTC](https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023/4 "2026-10-18T18:39:37Z")

</div>

Something like this:

```zig
fn ObesePointer(comptime T: type) type {
	return struct {
	    const Obese = @This();
	    
		ptr: [*]u8,
		stride: usize, // in bytes
		len: usize,
		
		const empty: Obese = .{
			.ptr = undefined,
			.stride = undefined,
			.len = 0,
		};
		
		
		fn init(comptime Container: type, comptime accessor: []const u8, slice: []Container) Obese {
			if (slice.len == 0) return .empty;
			return .{
				.ptr = @ptrCast(&@field(slice[0], accessor)),
				.stride = @sizeOf(Container),
				.len = slice.len,
			};
			
		}
		
		fn getPtr(self: Obese, i: usize) *T {
			std.debug.assert(i <= self.len);
			return @alignCast(@ptrCast(self.ptr + self.stride*i));
		}
		
		fn get(self: Obese, i: usize) T {
			return self.getPtr(i).*;
		}
		
	};
}

const Big = struct {
	point: [2]u8,
	id: usize,
};

pub fn main() void {
	var slices: [4]Big = @splat(.{.point = .{1,5}, .id = 3});
	
	const points: ObesePointer([2]u8) = .init(Big, "point", &slices);
	
	for (0..points.len) |i| {
		std.debug.print("{any}\n", .{points.get(i)});
	}
}

const std = @import("std");

```

---

<div class="post-metadata">

**Author:** ![nour](https://ziggit.dev/user_avatar/ziggit.dev/nour/32/10166_2.png) [@nour](https://ziggit.dev/u/nour)\
**Post date:** [October 18, 2026, 7:32pm UTC](https://ziggit.dev/t/looping-on-mytype-backed-by-mysupertype/18023/5 "2026-10-18T19:32:53Z")

</div>

Thank you this is great!  
I’ll tag you when I can show the result in action!
