June 07, 2016
On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote:
> They'd be the same type, since you would define the vulkan functions to take these structures instead of pointer or integer types.
>
> It relies on a lot of assumptions about the ABI that make a raw pointer work the same as a structure containing just one pointer, which is why I did not give it much consideration.

Is there a way to use opCast (just an idea, not working code) ?

private struct VK_HANDLE_HELPER {
	const void * handle = null;
	alias handle this;
	T opCast(T)() if( is( T == uint64_t )) {
		return 0uL;
	}
}
const VK_NULL_HANDLE = VK_HANDLE_HELPER();

June 07, 2016
On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote:
> It relies on a lot of assumptions about the ABI that make a raw pointer work the same as a structure containing just one pointer, which is why I did not give it much consideration.

At least some of those assumptions could be verified at compile time:

    // insert at the end of the VkHandle mixin template:
    static assert(typeof(this).sizeof == typeof(bits).sizeof);
    static assert(typeof(this).alignof == typeof(bits).alignof);

If you want to be extra careful, you can also use a string mixin to declare each extern(C) function with its official C parameter types, plus a D pragma(inline, true) wrapper that accepts VkDevice or whatever, instead.

Of course, it's probably a lot easier to just tel your users to replace VK_NULL_HANDLE with VK_NULL_DISPATCHABLE or VK_NULL_NONDISPATCHABLE like you suggested earlier.
June 07, 2016
On Tuesday, 7 June 2016 at 04:31:56 UTC, ParticlePeter wrote:
> On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote:
>> They'd be the same type, since you would define the vulkan functions to take these structures instead of pointer or integer types.
>>
>> It relies on a lot of assumptions about the ABI that make a raw pointer work the same as a structure containing just one pointer, which is why I did not give it much consideration.
>
> Is there a way to use opCast (just an idea, not working code) ?
>
> private struct VK_HANDLE_HELPER {
> 	const void * handle = null;
> 	alias handle this;
> 	T opCast(T)() if( is( T == uint64_t )) {
> 		return 0uL;
> 	}
> }
> const VK_NULL_HANDLE = VK_HANDLE_HELPER();


I don't think opCast gets called for implicit conversions; it only gets called for explicit casts. I'll test it later.
June 07, 2016
On Tuesday, 7 June 2016 at 14:31:40 UTC, Alex Parrill wrote:
> I don't think opCast gets called for implicit conversions; it only gets called for explicit casts. I'll test it later.

It does for type bool, but I fear that's the only exception.
June 07, 2016
On 06/07/2016 08:50 PM, ParticlePeter wrote:
> On Tuesday, 7 June 2016 at 14:31:40 UTC, Alex Parrill wrote:
>> I don't think opCast gets called for implicit conversions; it only
>> gets called for explicit casts. I'll test it later.
>
> It does for type bool, but I fear that's the only exception.

No, opCast can't be used for implicit conversions to bool.

I guess you're thinking of the `if(foo) {...}` case. That's considered an explicit conversion. `bool b = foo;` still won't work.
1 2
Next ›   Last »