Jump to page: 1 2 3
Thread overview
mixin template's alias parameter ... ignored ?
Jul 11, 2021
someone
Jul 11, 2021
Ali Çehreli
Jul 11, 2021
someone
Jul 12, 2021
someone
Jul 12, 2021
ag0aep6g
Jul 12, 2021
someone
Jul 12, 2021
jfondren
Jul 12, 2021
someone
Jul 13, 2021
Mike Parker
Jul 12, 2021
Ali Çehreli
Jul 13, 2021
someone
Jul 13, 2021
Ali Çehreli
Jul 13, 2021
someone
Jul 12, 2021
ag0aep6g
Jul 13, 2021
someone
Jul 13, 2021
Mike Parker
Jul 13, 2021
Mike Parker
Jul 13, 2021
someone
Jul 13, 2021
someone
Jul 13, 2021
ag0aep6g
Jul 13, 2021
someone
Jul 11, 2021
Adam D Ruppe
Jul 12, 2021
someone
Jul 11, 2021
zjh
Jul 11, 2021
Adam D Ruppe
Jul 11, 2021
zjh
Jul 11, 2021
zjh
Jul 12, 2021
someone
July 11, 2021
mixin template templateUGC (
   typeStringUTF,
   alias lstrStructureID
   ) {

   public struct lstrStructureID {

      typeStringUTF whatever;

   }

}

mixin templateUGC!(string,  "gudtUGC08");
mixin templateUGC!(dstring, "gudtUGC16");
mixin templateUGC!(wstring, "gudtUGC32");

void main() {

   gudtUGC32 something; /// Error: undefined identifier `gudtUGC32`

}

I cannot manage to get this right; not even with:

   public struct mixin(lstrStructureID) { ... }

because the argument seems to require a complete statement.

July 10, 2021
On 7/10/21 10:20 PM, someone wrote:

> mixin template templateUGC (
>     typeStringUTF,
>     alias lstrStructureID
>     ) {
>
>     public struct lstrStructureID {

The only way that I know is to take a string parameter and use it with a string mixin:

mixin template templateUGC (
   typeStringUTF,
   string lstrStructureID
   ) {

  mixin("public struct " ~ lstrStructureID ~ q{
      {
        typeStringUTF whatever;

      }
    });

}

mixin templateUGC!(string,  "gudtUGC08");
mixin templateUGC!(dstring, "gudtUGC16");
mixin templateUGC!(wstring, "gudtUGC32");

void main() {

   gudtUGC32 something;

}

Ali

July 11, 2021

On Sunday, 11 July 2021 at 05:54:48 UTC, Ali Çehreli wrote:

>

The only way that I know is to take a string parameter and use it with a string mixin:

Yes, that I tried, but the structure has a lot of lines of codes and so it is impractical and of course it will turn out difficult to debug.

Since this seems to be a dead-end I did reshuffle some things around:

/// for illustration purposes only:
alias stringUTF08 = string;  /// = immutable(char )[];
alias stringUTF16 = dstring; /// = immutable(dchar)[];
alias stringUTF32 = wstring; /// = immutable(wchar)[];

alias stringUGC08 = gudtUGC!(stringUTF08);
alias stringUGC16 = gudtUGC!(stringUTF16);
alias stringUGC32 = gudtUGC!(stringUTF32);

public struct gudtUGC(typeStringUTF) {

   typeStringUTF whatever;

   ... lots of functions using typeStringUTF here

}

void main() {

   version (useUTF08) { stringUGC08 lugcSequence3 = stringUGC08(r"..."c); }
   version (useUTF16) { stringUGC16 lugcSequence3 = stringUGC16(r"..."d); }
   version (useUTF32) { stringUGC32 lugcSequence3 = stringUGC32(r"..."w); }

}

It works.

Thanks Ali :) !

July 11, 2021

On Sunday, 11 July 2021 at 05:20:49 UTC, someone wrote:

>
mixin template templateUGC (
   typeStringUTF,
   alias lstrStructureID
   ) {

   public struct lstrStructureID {

      typeStringUTF whatever;

   }

This creates a struct with teh literal name lstrStructureID. Just like any other name. So it is NOT the value of the variable.

>
   public struct mixin(lstrStructureID) { ... }

because the argument seems to require a complete statement.

Indeed, you'd have to mixin the whole thing like

mixin("public struct " ~ lstrStructureId ~ " { ... } ");

July 11, 2021

On 7/11/21 8:49 AM, Adam D Ruppe wrote:

>

On Sunday, 11 July 2021 at 05:20:49 UTC, someone wrote:

>
mixin template templateUGC (
   typeStringUTF,
   alias lstrStructureID
   ) {

   public struct lstrStructureID {

      typeStringUTF whatever;

   }

This creates a struct with teh literal name lstrStructureID. Just like any other name. So it is NOT the value of the variable.

>
   public struct mixin(lstrStructureID) { ... }

because the argument seems to require a complete statement.

Indeed, you'd have to mixin the whole thing like

mixin("public struct " ~ lstrStructureId ~ " { ... } ");

when I've done this kind of stuff, what I usually do is:

struct Thing {
  ... // actual struct
}

mixin("alias ", lstrStructureID, " = Thing;");

the downside is that the actual struct name symbol will be Thing, or whatever you called it. But at least you are not writing lots of code using mixins.

-Steve

July 11, 2021

On Sunday, 11 July 2021 at 12:49:28 UTC, Adam D Ruppe wrote:

>

This creates a struct with teh literal name lstrStructureID. Just like any other name. So it is NOT the value of the variable.

Could you explain more detail?

July 11, 2021

On Sunday, 11 July 2021 at 13:30:27 UTC, zjh wrote:

>

Could you explain more detail?

It is just normal code with a normal name. The fact there's another variable with the same name doesn't change anything.

July 11, 2021
mixin template templateUGC ( typeStringUTF, alias lstrStructureID){
   public struct lstrStructureID {
      typeStringUTF w;
   }
}
mixin templateUGC!(string,  "gudtUGC08");

You say This creates a struct with teh literal name lstrStructureID.
I tried,can compile,but I don't know generate what.

Could you explain more detail?

July 11, 2021

On Sunday, 11 July 2021 at 14:04:14 UTC, zjh wrote:

just genenrate lstrStructureID struct.

July 12, 2021

On Sunday, 11 July 2021 at 12:49:28 UTC, Adam D Ruppe wrote:

>

Indeed, you'd have to mixin the whole thing like

mixin("public struct " ~ lstrStructureId ~ " { ... } ");

As I mentioned in my previous reply to Ali this could be viable for one-liners-or-so, but for chunks of code having, say, a couple hundred lines for one UDT, it will become debug/maintenance-hell soon ... so clearly; it is a no-go ... for my specific case at least.

« First   ‹ Prev
1 2 3