Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Range cast #6

Closed
Tracked by #3
kassane opened this issue Dec 30, 2023 · 3 comments
Closed
Tracked by #3

Rework Range cast #6

kassane opened this issue Dec 30, 2023 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@kassane
Copy link
Owner

kassane commented Dec 30, 2023

No description provided.

@kassane kassane added the enhancement New feature or request label Dec 30, 2023
@kassane
Copy link
Owner Author

kassane commented Jan 2, 2024

Current:

sokol-d/src/sokol/gfx.d

Lines 11 to 25 in 6f0b30e

// WIP: helper function to convert "anything" to a Range struct
Range asRange(T)(T val) @trusted {
import std.traits;
static if (isPointer!T) {
return Range(val, T.sizeof);
} else static if (is(T == float[]) || is(T == double[])) {
auto arr = val.dup;
return Range(&arr[0], arr.length * arr[0].sizeof);
} else static if (is(T == struct)) {
Range r = {ptr: cast(const(void)*)&val, size: T.sizeof};
return r;
} else {
static assert(0, "Cannot convert to range");
}
}

Why not @safe?

/home/kassane/sokol-d/src/sokol/gfx.d(21,15): Error: scope variable `r` may not be returned
       return r;
              ^
/home/kassane/sokol-d/src/examples/cube.d(116,28): Error: template instance `sokol.gfx.asRange!(VsParams)` error instantiating
    sg.Range r = sg.asRange(vsParams);
                           ^
ldc2: error: the following command exited with error code 1:

@kassane kassane mentioned this issue Jan 2, 2024
13 tasks
@kassane
Copy link
Owner Author

kassane commented Jan 13, 2024

moved to sokol.utils: c088de5

Still considering the necessity for this cast or simply discarding it. Though it won't be applied or auto-generated anymore.

@kassane kassane added help wanted Extra attention is needed question Further information is requested labels Jan 13, 2024
@kassane
Copy link
Owner Author

kassane commented May 12, 2024

@kassane kassane closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant