midrare
midrare

Reputation: 2784

Overloading bool operator in D

In C++ you would overload operator bool() const. In Python, you would override __bool__(). What can I do in D to achieve the same result? I can't find any examples on this.

Upvotes: 3

Views: 95

Answers (1)

Adam D. Ruppe
Adam D. Ruppe

Reputation: 25605

Look for "Boolean Operations" on this page: http://dlang.org/operatoroverloading.html

You implement a member function like:

bool opCast(T : bool)() {
     return bool_result;
}

Upvotes: 4

Related Questions