uint[3] not equivalent to void[12]?

Ralph Doncaster nerdralph at github.com
Fri Feb 9 17:16:32 UTC 2018


On Friday, 9 February 2018 at 16:28:50 UTC, Nicholas Wilson wrote:
> On Friday, 9 February 2018 at 15:50:24 UTC, Ralph Doncaster 
> wrote:
>>Is there a way I can make a function that takes an array of any 
>>type but only of a specific size in bytes?
>
> With a template that constrains the types size:
>
> void foo(T)(T t) if (T.sizeof == 12)
> {
>     //...
> }
>
> alternately reject incorrect values at runtime
>
> void foo(ubyte[] t)
> in
> {
>     assert(t.length == 12);
> }
> do
> {
>     //...
> }

Thanks.  That's what I thought.  If I stick with using D, I'll 
probably go with the runtime check.



More information about the Digitalmars-d-learn mailing list