On Monday, 5 May 2014 at 03:57:54 UTC, Andrey wrote:

A similar D code is, as far as I know,

type.field.offsetof

Is there an any way to make a corresponding D template?

What you've written is the specific syntax for offsetof in D.

If the intent is to create a template so that you can simply find/replace offsetof(type,field) with offsetoftemplate!(type,field) then I think it is easier to create a sed script - better yet a D program - for replacing the C macro with D code.

Example program:
import std.array;
import std.file;
import std.regex;
import std.string;
int main(string[] args)
{
        if (args.length < 2)
                return -1;
        auto regex = ctRegex!(`offsetof\(([^,]+),([^)]+)\)`);
        auto sink = appender!(char[])();
        foreach (filename; args[1..$])
        {
                auto text = readText(filename);
                sink.reserve(text.length);
replaceAllInto!(cap => cap[1].strip~"."~cap[2].strip~".offsetof")(sink, text, regex);
                write(filename, sink.data);
                sink.clear();
        }
        return 0;
}

Reply via email to