[suggestion] importing and renaming by wildcard and/or regexp

Paul Backus snarwin at gmail.com
Wed Jul 27 13:41:00 UTC 2022


On Thursday, 21 July 2022 at 22:08:14 UTC, AnimusPEXUS wrote:
> Why?: for example I have module bindbc.glfw - It have symbols 
> like GLFW_KEY_* so I want to import only GLFW_KEY symbols.
>
> additionally: "Renamed and Selective Imports" with renaming by 
> using regexp groups, so for example if I want to import 
> GLFW_KEY_(\w+) and rename those like so MY_KEY_$1

You can try something like this:

```d
struct MY_KEY
{
     template opDispatch(string name)
     {
         static import bindbc.glfw;
         mixin(`alias opDispatch = bindbc.glfw.GLFW_KEY_`, name, 
`;`);
     }
}
```

This will let you write `MY_KEY.FOO` and get an alias for 
`GLFW_KEY_FOO`.


More information about the Digitalmars-d mailing list