"%s"-format template function arguments

2018-04-15 Thread vladdeSV via Digitalmars-d-learn

Hello people of D-land.

In a template function, I want to format all arguments as if it 
was an array. Se this snippet of code:


void foo(T...)(T args)
writefln("expected: %s", [1,2,3]);
writefln("actual: %s", args);

The code above will output

expected: [1, 2, 3]
actual: 1

How would I go on about to print all the arguments as I expected 
it, using "%s"?

Best regards,
Vladimirs Nordholm


I do not understand why only a `1` is printed in the actual 

@property get/set or public varaible?

2016-12-04 Thread vladdeSV via Digitalmars-d-learn


I have a question not directly related to D as it is with coding 

My issue at hand is if I have one variable for a class, which I 
want to be directly accessible for anything else, should it be

 1. public, or
 2. private, with @property get/setters?

From what I have been told is that variables should be private. 
But if I do not want to make any checks whatsoever when setting a 
variable, I see no benefit to the private approach.

Are there any other reasons to use get/setters?

Re: Access vialotion

2016-06-22 Thread vladdeSV via Digitalmars-d-learn

On Wednesday, 22 June 2016 at 12:47:31 UTC, TheDGuy wrote:

On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote:

I have an array of buttons:

class Window : MainWindow{
private Button[4] bArr;
Button btn_1 = new Button();
Button btn_2 = new Button();
Button btn_3 = new Button();
Button btn_4 = new Button();
Button[4] bArr = [btn_1,btn_2,btn_3,btn_4];
private void letButtonsFlash(){
for(int i = 0; i < 4; i++){

i don't understand why i get an 'Access Violation' - Error in 
the 'for'-loop?

Okay, i solved it, instead of:
Button[4] bArr = [btn_1,btn_2,btn_3,btn_4];

bArr = [btn_1,btn_2,btn_3,btn_4];

I would also suggest you use a foreach loop to iterate over the 

private void letButtonsFlash()
foreach(button; bArr)

//Also, question to anyone: should a ref be used here?