Jump to page: 1 2 3
Thread overview
Allow designated initialization of struct
Aug 30, 2024
ryuukk_
Aug 30, 2024
ryuukk_
Nov 01, 2024
f
Aug 30, 2024
monkyyy
Aug 31, 2024
ryuukk_
Sep 12, 2024
ryuukk_
Sep 12, 2024
Sergey
Sep 12, 2024
ryuukk_
Sep 12, 2024
Serg Gini
Sep 12, 2024
ryuukk_
Sep 13, 2024
Nick Treleaven
Sep 13, 2024
ryuukk_
Nov 02, 2024
IchorDev
Oct 21, 2024
ryuukk_
Oct 26, 2024
Salih Dincer
Oct 30, 2024
ryuukk_
Oct 31, 2024
Salih Dincer
Nov 01, 2024
ryuukk_
Nov 02, 2024
IchorDev
Nov 02, 2024
Nick Treleaven
Nov 08, 2024
IchorDev
Nov 12, 2024
Dennis
Nov 12, 2024
IchorDev
Nov 15, 2024
Salih Dincer
Nov 03, 2024
Salih Dincer
August 30, 2024

This should be allowed:

struct Data
{
    int a;
    int b;
    int c;
    @disable this();
}

my_fun( Data { c: 1 } );
August 30, 2024

And in a perfect world:

my_fun( { c: 1 } );
August 30, 2024

On Friday, 30 August 2024 at 16:02:38 UTC, ryuukk_ wrote:

>

This should be allowed:

struct Data
{
    int a;
    int b;
    int c;
    @disable this();
}

my_fun( Data { c: 1 } );

the debate is about nested stucts being spooky

struct nullable(T){
  T get; alias get this;
  bool isnull=false;
  ...
}
struct runtime{
  this(int i){
    i.writeln;
}}
nullable!T somethingfailable(T)(T t){
  return nullable!T(isnull:true);
}

the compiler gets confused, whats a somethingfailable.get?

Im of the strong opinion that d should just let spookiness happen, if "ctfe this" fails to produce sane results, thats on the programmer, let it happen; but you "need" to "solve" the "problem" to suggest changes here.

August 30, 2024

On Friday, 30 August 2024 at 16:02:38 UTC, ryuukk_ wrote:

>

This should be allowed:

struct Data
{
    int a;
    int b;
    int c;
    @disable this();
}

my_fun( Data { c: 1 } );

I'm not understanding the @disable this()

Without that, this works:

struct Data
{
    int a;
    int b;
    int c;
}

void my_fun(Data data) {}

void main()
{
    my_fun( Data (c: 1 ) );
}

I tried making Data also have a ctor with all defaults, but it doesn't like that.

-Steve

August 31, 2024

On Friday, 30 August 2024 at 19:37:22 UTC, Steven Schveighoffer wrote:

>

On Friday, 30 August 2024 at 16:02:38 UTC, ryuukk_ wrote:

>

This should be allowed:

struct Data
{
    int a;
    int b;
    int c;
    @disable this();
}

my_fun( Data { c: 1 } );

I'm not understanding the @disable this()

Without that, this works:

struct Data
{
    int a;
    int b;
    int c;
}

void my_fun(Data data) {}

void main()
{
    my_fun( Data (c: 1 ) );
}

I tried making Data also have a ctor with all defaults, but it doesn't like that.

-Steve

brackets vs parenthesis, no ctor

it's popular among C and newest languages (the irony), data first

D lags behind, as usual

    state.pip = sg_make_pipeline(&(sg_pipeline_desc){
        .layout = {
            /* test to provide buffer stride, but no attr offsets */
            .buffers[0].stride = 28,
            .attrs = {
                [ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
                [ATTR_vs_color0].format   = SG_VERTEXFORMAT_FLOAT4
            }
        },
        .shader = shd,
        .index_type = SG_INDEXTYPE_UINT16,
        .cull_mode = SG_CULLMODE_BACK,
        .depth = {
            .write_enabled = true,
            .compare = SG_COMPAREFUNC_LESS_EQUAL,
        },
        .label = "cube-pipeline"
    });

September 12, 2024

Today i tried this:



struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add( Data(test: [ {test: 1}] ) );
}

it refuses to compile:

onlineapp.d(19): Error: found `}` when expecting `;` following expression
onlineapp.d(19):        expression: `1`
onlineapp.d(19): Error: found `]` instead of statement
onlineapp.d(21): Error: found `End of File` when expecting `,`
onlineapp.d(19): Error: found `End of File` when expecting `]`
onlineapp.d(21): Error: found `End of File` when expecting `)`
onlineapp.d(21): Error: found `End of File` when expecting `)`
onlineapp.d(21): Error: found `End of File` when expecting `;` following expression
onlineapp.d(19):        expression: `add(Data(test: [()
{
test:
1;
__error__
}
]))`
onlineapp.d(21): Error: matching `}` expected following compound statement, not `End of File`
onlineapp.d(18):        unmatched `{`

D worse than C with these stupid RAII, give me proper way to initialize a struct instead of giving me a broken constructor i'm not even using

September 12, 2024

On Thursday, 12 September 2024 at 12:14:17 UTC, ryuukk_ wrote:

>

Today i tried this:



struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add( Data(test: [ {test: 1}] ) );
}

struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add(Data(Test(1).repeat(8).array.to!(Test[8])));
}

What did you expect to initializing an array of 8 elements with 1 value? all the same?

September 12, 2024

On Thursday, 12 September 2024 at 13:10:09 UTC, Sergey wrote:

>

On Thursday, 12 September 2024 at 12:14:17 UTC, ryuukk_ wrote:

>

Today i tried this:



struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add( Data(test: [ {test: 1}] ) );
}

struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add(Data(Test(1).repeat(8).array.to!(Test[8])));
}

What did you expect to initializing an array of 8 elements with 1 value? all the same?

What did i expect?.. right i expect to switch language as soon as i find an alternative

Besides

Test[8] test = Test.init; // <- works

Data data = { test: Test.init }; // <- works

char[256] path = "/dev/null"; // <- works

Again, what do YOU expect?

D people still don't understand why the language is not more popular and why people leave after they play with it

I grew tired of trying to explain people how shitty things are for so long, wake up please

September 12, 2024
>

add(Data(Test(1).repeat(8).array.to!(Test[8])));

I'm not sure if you are joking or not, i'll pretend this was a mistake of yours

September 12, 2024

On Thursday, 12 September 2024 at 13:46:55 UTC, ryuukk_ wrote:

>

Again, what do YOU expect?

D people still don't understand why the language is not more popular and why people leave after they play with it

I grew tired of trying to explain people how shitty things are for so long, wake up please

I see now what you want. Wasnt clear for me from the first look.
Only named example worked yeah

« First   ‹ Prev
1 2 3