digitalmars.D.learn - Can operators "return" type?
- Zhenya (7/7) Nov 29 2012 Hi!
- bearophile (10/13) Nov 29 2012 D operators are functions, and D functions return values. And in
- Zhenya (10/23) Nov 29 2012 Of course I understand,that type is not value in D.I meant that
- bearophile (4/12) Nov 29 2012 As you guess, this is not supported in D.
- Zhenya (2/15) Nov 29 2012 Thank you,understood(
- Simen Kjaeraas (5/12) Nov 29 2012 This works out of the box. If you want to define your own
Hi! It would useful for some my project,if operators could be a template,that "return" type.Something like alias TypeTuple!(int,char) types; static assert(types[1] == char) //opIndex So can I define something like that?
Nov 29 2012
Zhenya:It would useful for some my project,if operators could be a template,that "return" type.D operators are functions, and D functions return values. And in D types are not values (unlike Python and several other languages), unless you use a Typeinfo or something. Maybe if you explain better what you are trying to do someone will be able to suggest you an alternative solution. D is not as flexible as Lisp, but it doesn't lack meta-programming/type-processing capabilities. Bye, bearophile
Nov 29 2012
On Thursday, 29 November 2012 at 16:55:01 UTC, bearophile wrote:Zhenya:Of course I understand,that type is not value in D.I meant that maybe we can declare non-function template operators.For example: struct MyIntType { alias int type; template opSlice() { alias type opSlice; }It would useful for some my project,if operators could be a template,that "return" type.D operators are functions, and D functions return values. And in D types are not values (unlike Python and several other languages), unless you use a Typeinfo or something. Maybe if you explain better what you are trying to do someone will be able to suggest you an alternative solution. D is not as flexible as Lisp, but it doesn't lack meta-programming/type-processing capabilities. Bye, bearophile
Nov 29 2012
Zhenya:For example: struct MyIntType { alias int type; template opSlice() { alias type opSlice; }As you guess, this is not supported in D. Bye, bearophile
Nov 29 2012
On Thursday, 29 November 2012 at 21:53:20 UTC, bearophile wrote:Zhenya:Thank you,understood(For example: struct MyIntType { alias int type; template opSlice() { alias type opSlice; }As you guess, this is not supported in D. Bye, bearophile
Nov 29 2012
On 2012-11-29, 17:33, Zhenya wrote:Hi! It would useful for some my project,if operators could be a template,that "return" type.Something like alias TypeTuple!(int,char) types; static assert(types[1] == char) //opIndex So can I define something like that?This works out of the box. If you want to define your own TypeTuple-like construct, the answer is most likely going to be no. -- Simen
Nov 29 2012