Would it be possible (and useful) to introduce declarations like `auto foo() if(isInputRange(auto));
Jonathan M Davis
jmdavisProg at gmx.com
Thu May 17 11:52:32 PDT 2012
`
To: "digitalmars.D" <digitalmars-d at puremagic.com>
User-Agent: KMail/4.8.2 (Linux/3.3.1-1-ARCH; KDE/4.8.2; x86_64; ; )
X-Authenticated: #68274723
X-Flags: 0001
X-KMail-CryptoMessageFormat: 15
X-KMail-EncryptActionEnabled: false
X-KMail-Fcc: 15
X-KMail-SignatureActionEnabled: false
X-KMail-Transport: 1406625660
X-Mailer: GMX.com Web Mailer
x-registered: 0
X-GMX-UID: pi3HbzE+3zOlOEKpenAhypZ+IGRvb0CJ
On Thursday, May 17, 2012 13:49:16 Roman D. Boiko wrote:
> Is there anything preventing us from adding constraints on the
> auto function return value? I mean, such language extension seems
> to be quite useful.
>
> For example, it would be no longer necessary to provide method
> bodies for functions with auto return values.
>
> In many cases this would eliminate the need for introducing an
> interface.
>
> interface returnsDuckTyped
> {
> auto foo() if(isInputRange(auto));
> }
It would still be necessary, because the compiler needs to know what the
actual return type is. Knowing that the type implements popFront, front, and
empty isn't enough. It needs to know the actual, physical layout of the type
to generate the proper code. And when dealing with an interface, the return
type must be covariant, and unless the types are both classes and one is
derived from the other (directly or indirectly), they won't be covariant even
if they have all of the same functions.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list