On 06/26/2014 10:58 PM, pgtkda wrote:
What does this symbol mean in relation to D?

~

It can be used in two ways:

1) When used as a unary operator, it means bitwise complement:

    assert(~0xaa55aa55 == 0x55aa55aa);

2) When used as a binary operator, it means concatenation:

    assert("hello" ~ " world" == "hello world");

    auto arr = [ 1, 2 ];
    assert(arr ~ 3 == [ 1, 2, 3 ]);

When used with assignment, it means appending:

    auto arr = [ 1, 2 ];
    arr ~= 3;

    assert(arr == [ 1, 2, 3 ]);

It can also be used in the special function name ~this(), which is the destructor of a struct or a class. (Related functions: 'static ~this()' and 'shared static ~this()')

Ali

[1] http://ddili.org/ders/d.en/bit_operations.html

[2] http://ddili.org/ders/d.en/arrays.html

[3] ddili.org/ders/d.en/special_functions.html

  • ~ ? pgtkda via Digitalmars-d-learn
    • Re: ~ ? Ali Çehreli via Digitalmars-d-learn
      • Re: ~ ? pgtkda via Digitalmars-d-learn
    • Re: ~ ? Chris via Digitalmars-d-learn

Reply via email to