Idea : Expression Type
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Fri Feb 2 11:50:51 PST 2007
Xinok wrote:
> Functions aren't powerful enough to be used in place of expressions.
>
> -- Functions can't return references, which prevents you from using them as l-values. The best you can do is return a pointer, which you have to manually dereference.
> -- All of the types in an expression are automatic, including the return type. Getting the parameter types for a function can be simple, but the return type can be difficult.
> -- Functions can't take full advantage of features like conditionals, because conditionals can have two or more possible 'return types'. Functions can only return a single type.
Conditionals always have one return type that can be detected as
typeof(true? T : U).
The advantage of expression aliases is that indeed there's no need to
worry for their type. Also, expression aliases work when passing e.g.
constant expressions to templates because they expand during
compilation. The disadvantages are that (1) writing statements in the
replacement expression is not possible, (2) separate compilation is not
possible.
Andrei
More information about the Digitalmars-d
mailing list