Where should I put a `condp` like function?

Nick Treleaven ntrel-public at yahoo.co.uk
Wed Apr 17 06:09:47 PDT 2013


On 15/04/2013 06:00, H. S. Teoh wrote:
> Allowing arbitrary predicates and switch-as-expression allows you to
> write code that shows intent very clearly:
>
> 	// In pseudo-D syntax
> 	void fill(T)(T image, int x, int y) {
> 		image[x,y] = switch {
> 			case isFillable(image,x,y): fillColor;
> 			case isBorder(image,x,y): borderColor;
> 			default: defaultColor;
> 		};
> 	}

We could use a conditional operator chain:

image[x,y] = isFillable(image,x,y) ? fillColor :
              isBorder(image,x,y) ? borderColor :
              defaultColor;


More information about the Digitalmars-d mailing list