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

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 21 12:20:00 PST 2015


On 12/21/15 12:03 PM, anonymous wrote:
> 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 */
> ----

This seems like an incorrect feature then. Why wouldn't I want S to be 
treated like any other const(char)*? Seems like it's explicitly saying 
"treat this like a const(char)*"

-Steve


More information about the Digitalmars-d-learn mailing list