Thread overview
code formatting issue
Oct 02, 2013
Alexandr Druzhinin
Oct 02, 2013
bearophile
Oct 02, 2013
Alexandr Druzhinin
Oct 02, 2013
bearophile
October 02, 2013
I'm curious what is the best way to code like this:

//		    request_id  zoom  x     y     path    url
auto msg = receiveOnly!(size_t, zoom, uint, uint, string, string)();

or like this

auto msg = receiveOnly!(
	typeof(request_id),
	typeof(zoom),
	typeof(x),
	typeof(y),
	typeof(path),
	typeof(url)
)();

Or may be I'm worrying about nonsense and better I'd start thinking about more useful things? :)
October 02, 2013
Alexandr Druzhinin:

> auto msg = receiveOnly!(
> 	typeof(request_id),
> 	typeof(zoom),
> 	typeof(x),
> 	typeof(y),
> 	typeof(path),
> 	typeof(url)
> )();
>
> Or may be I'm worrying about nonsense and better I'd start thinking about more useful things? :)

It's often a good idea to use typeof to keep the code more DRY and safer.

Another possible solution is to put the variables in some kind of tuple, take its types and use them with a trailing [] to pass them all to receiveOnly.

Bye,
bearophile
October 02, 2013
02.10.2013 22:47, bearophile пишет:
>
> It's often a good idea to use typeof to keep the code more DRY and safer.
>

I'm sure keeping the code dry and clean is very good idea, but using typeof is rather verbose and just is unusual and verbose a little bit.

> Another possible solution is to put the variables in some kind of tuple,
> take its types and use them with a trailing [] to pass them all to
> receiveOnly.
>
> Bye,
> bearophile

Something like this:

alias Tuple!(
    typeof(request_id),
    typeof(zoom),
    typeof(x),
    typeof(y),
    typeof(path),
    typeof(url)
) TileDescription;

// wait for tile descripton to process
auto msg = receiveOnly!TileDescription();

? I didn't understand about trailing []
October 02, 2013
Alexandr Druzhinin:

> ? I didn't understand about trailing []

I meant something more like this, but I don't know how much of an improvement this is:


import std.typecons, std.typetuple;

template Foo(T1, T2) {
    enum Foo = 1;
}

void main() {
    int x;
    float f;
    enum y = Foo!(typeof(TypeTuple!(x, f)));
}


Bye,
bearophile