On Tuesday, 9 April 2024 at 12:45:55 UTC, Richard (Rikki) Andrew Cattermole wrote:

On 09/04/2024 12:48 PM, Liam McGillivray wrote:

I suppose this was a good new thing to learn, though I'm still quite far from being able to construct a function from another function using a template.

I suppose that if I wanted it to make a function from another function, I may be able to do it in a template using some `static foreach` to make arrays of function parameters, and then combine them together without the use of strings, instead using placeholders (aliases or whatever they'd be called) and maybe the `tupleof` function. Am I headed in the right direction (if you can understand my weak attempt to describe the direction I'm thinking of going in)?

``tupleof`` isn't a function, its a property to get a "tuple" a sequence of fields for a struct/class.

However most likely you'd have to resort to string mixins if you're messing about with parameters like I think? you are asking for.

I'm not entirely sure what you're wanting there.

Here's what I wanted to do.

In the library I'm working on, there are various declarations for functions defined in an external C library following the line `extern (C) @nogc nothrow:`. Here are some examples of such declarations which have a `const(char)*` parameter:
```
void InitWindow(int width, int height, const(char)* title);
void SetWindowTitle(const(char)* title);
Shader LoadShader(const(char)* vsFileName, const(char)* fsFileName);
```

I wanted to generate definitions of overloads of these functions using strings as parameters instead of `const(char)*`. For the `InitWindow` function shown above, the overload should be defined like this:
```
void InitWindow(int width, int height, ref string title) {
    InitWindow(width, height, cast(const(char)*)title);
}
```
or alternatively, like the following:
```
void InitWindow(int width, int height, string title) {
    InitWindow(width, height, title.toStringz);
}
```

I'm not sure which of these is better, thought the latter one would need to be modified to not accept string literals. I found that the former one has the advantage that making the `title` parameter `ref string` means that string literals use the existing version of the function. I know that the former can be `@nogc`, unlike the latter, though I don't know if there is any advantage offered by `toStringz` over `cast(const(char)*)`.

But anyway, my goal was to generate function overloads like either of the above. I have already posted a version of a CTFE function that does this, though I put them under `version (D_TypeInfo)` so that they aren't available in `betterC` builds, since the function I wrote doesn't build with `betterC`.
  • "Error: `Ty... Liam McGillivray via Digitalmars-d-learn
    • Re: "E... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: &qu... Liam McGillivray via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... Liam McGillivray via Digitalmars-d-learn
            • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
              • ... Liam McGillivray via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... Liam McGillivray via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... Liam McGillivray via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: &qu... Liam McGillivray via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... Liam McGillivray via Digitalmars-d-learn
            • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
          • ... Steven Schveighoffer via Digitalmars-d-learn
    • Re: "E... Kagamin via Digitalmars-d-learn

Reply via email to