What does 'inline' mean?

Manu turkeyman at gmail.com
Sat Jun 13 00:35:44 UTC 2020


On Sat, Jun 13, 2020 at 6:15 AM Avrina via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Friday, 12 June 2020 at 15:37:16 UTC, Andrei Alexandrescu
> wrote:
> > On 6/11/20 11:01 PM, Avrina wrote:
> >> On Friday, 12 June 2020 at 01:55:26 UTC, Manu wrote:
> >>> Can you please explain why you feel opposed to this, and why
> >>> our existing
> >>> solution, which is 'weird' by all accounts, and satisfies
> >>> ZERO of the goals
> >>> assigned to inline is preferable?
> >>
> >> You won't get a direct answer to this. You can't have a debate
> >> if he never presents an argument. Or rather in business, you
> >> don't have to deal with a problem if you don't acknowledge
> >> there is a problem, management 101.
> >
> > It seems to me the problem lies with the way the problem is
> > formulated.
>
> You managed to figure it out :), at least better than Walter.
> When talking about inline, it seems even you and Walter seem to
> be focused on the "inline" part.
>
> Yes an empty template does what Manu wants, the problem is that
> templates have their own nasty side effects.
>
>     int  foo(int)  { return 1; }
>     bool foo(bool) { return true; }
>
>     int  bar()(int)  { return 1; }
>     bool bar()(bool) { return true; }
>
>     pragma(msg, __traits(getOverloads, __traits(parent, foo),
> "foo")); // tuple of (foo, foo)
>     pragma(msg, __traits(getOverloads, __traits(parent, bar),
> "bar")); // empty tuple ()
>

Right, this is but one of an endless sea of edge cases extending from the
fact that templates are not functions, they are templates... they may
become functions when they are instantiated, but that requires
instantiation.
Basically the only way that a nullary template function is like a normal
function is a direct call: `foo()`, almost anything else you do has
sufficient semantic differences that break interactions with generic code.

Eg:
    void foo() {}
    void bar()() {}

    // this works (this is the only thing that works):
    foo();
    bar();

    // this doesn't:
    auto x = &foo;
    auto y = &bar;

    // this doesn't:
    static assert(is(typeof(foo) == function));
    static assert(is(typeof(bar) == function));

    // this doesn't:
    pragma(msg, __traits(getOverloads, __traits(parent, foo), "foo")); //
(foo)
    pragma(msg, __traits(getOverloads, __traits(parent, bar), "bar")); // ()

    // etc...

Dummy templates are not a cool workaround. Sometimes functions are just
meant to be functions.
What the template hack does show us though, is that DMD is already
perfectly capable of implementing `inline`, it's probably a 1-line fix.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200613/b8ce13b9/attachment-0001.htm>


More information about the Digitalmars-d mailing list