digitalmars.D - Would it be possible (and useful) to introduce declarations like `auto
- Roman D. Boiko (11/11) May 17 2012 Is there anything preventing us from adding constraints on the
- Roman D. Boiko (6/13) May 17 2012 interface returnsDuckTyped
- Jonathan M Davis (22/36) May 17 2012 `
- Roman D. Boiko (3/17) May 17 2012 I felt there is some fundamental problem, otherwise it would have
- Jonathan M Davis (9/23) May 17 2012 It would still be necessary, because the compiler needs to know what the...
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)); }
May 17 2012
On Thursday, 17 May 2012 at 11:49:18 UTC, 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); } (fixed typo)
May 17 2012
` To: "digitalmars.D" <digitalmars-d puremagic.com> User-Agent: KMail/4.8.2 (Linux/3.3.1-1-ARCH; KDE/4.8.2; x86_64; ; ) 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
May 17 2012
On Thursday, 17 May 2012 at 21:09:10 UTC, Jonathan M Davis wrote: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 DavisI felt there is some fundamental problem, otherwise it would have been implemented already. But couldn't find any myself. Thanks!
May 17 2012
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
May 17 2012