What other than a pointer can be converted implicitly to const(char)*?

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 21 09:03:00 PST 2015


On 21.12.2015 17:02, Shriramana Sharma wrote:
> https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L878
>
> The `static if` condition here says if something is a pointer and if it is
> implicitly convertible to const(char)*. The isPointer! part seems
> superfluous. Is there something that is not a pointer yet implicitly
> convertible to const(char)*?

A struct/class with an `alias this` to a `const(char)*`:

----
import std.traits: isPointer;

struct S
{
     const(char)* ptr;
     alias ptr this;
}

static assert(!isPointer!S && is(S : const(char)*)); /* passes */
----


More information about the Digitalmars-d-learn mailing list