[:] as empty associative array literal, plus warning for null

NotYetUsingD do_not_reply at this_message.com
Thu Jul 4 11:36:24 PDT 2013


On Thursday, 4 July 2013 at 18:03:02 UTC, Andrei Alexandrescu 
wrote:
> A null array _is_ an empty array.

Proof (I'm sorry for not using D):

#include <cstddef>
#include <iostream>

int main()
{
    int* a = nullptr;
    int length = 0;
    int offset = 7;

    bool is_empty_0 = &a[0] - &a[length];
    bool is_empty_1 = a - a;
    bool is_empty_2 = (a + offset) - (a + offset);
    bool is_empty_3 = &(a + offset)[0] - &(a + offset)[length];

    std::cout << is_empty_0 << std::endl;
    std::cout << is_empty_1 << std::endl;
    std::cout << is_empty_2 << std::endl;
    std::cout << is_empty_3 << std::endl;
}


More information about the Digitalmars-d mailing list