On Friday, 14 July 2023 at 01:34:54 UTC, Steven Schveighoffer wrote:
On 7/13/23 8:08 PM, Cecil Ward wrote:

What I really want to do though is provide one single templated function with the kind of characters / strings as a parameter. I want to have something like
T Transform( T )( T str)
called as
auto result = Transform!(dstring)( dstring str );

```d
T[] Transform(T)(T[] str)
```

Note that you don't have to specify the type when calling:

```d
Transform(someDstring); // infers dchar
```

I’m quite confused as to how to proceed. This is quite a large module ~ 2k loc, and I don’t really want to go through and change every private function into a templated one. Should I just make the whole thing into a giant template containing many functions?

If you have more questions, please ask. Some examples of how making a template would be painful would be helpful.

-Steve

The way I can see it going is a giant template encompassing pretty much the whole file. Does that mean that the caller who calls my one public function does so by passing the type dchar or wchar ? And then we generate the strings from that. It might be rather more natural for the caller to pass one of the string types into the template. That’s where I get rather more confused, say caller calls

Transform(dstring)(dstring str)

or can they just do Transform( "str"d ) and it would work out that the type is immutable dchar[] ?

Reply via email to