digitalmars.D - Possible syntax for multiple opCast functions
- B Shropshire (7/7) Jul 12 2005 How about treat the opCast function as if it were a template:
- zwang (3/19) Jul 12 2005 more intuitive.
- Victor Nakoryakov (8/32) Jul 12 2005 I find opCast superfluous. Since implicit casts are not allowed anyway
- Regan Heath (9/35) Jul 13 2005 I'd argue the only time implicit casts would make some sense would be fo...
- Stewart Gordon (16/19) Jul 13 2005 Been suggested before.
- Stewart Gordon (16/24) Jul 13 2005 This would indeed be a new syntax. If you're going to do this, why not
- Ender KaShae (3/13) Jul 20 2007 rather than have multiple cast use functions like toInt, toChar, toB, fo...
-
Stewart Gordon
(7/10)
Jul 20 2007
"Ender KaShae"
wrote in message - BCS (2/3) Jul 20 2007 bad link
- Stewart Gordon (4/6) Jul 20 2007 Works for me at the moment.
- BCS (2/13) Jul 20 2007 OK, works now (must be a non D system :)
- Stewart Gordon (5/7) Jul 20 2007 Does this one work for you?
- BCS (2/18) Jul 20 2007 ?? I don't follow.
How about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }
Jul 12 2005
B Shropshire wrote:How about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }I findClass A { int opCast(int) { ... } // the opCast operator for casting to int char opCast(char) { ... } // the opCast operator for casting to char B opCast(B) { ... } // the opCast operator for casting to B }more intuitive.
Jul 12 2005
zwang wrote:B Shropshire wrote:I find opCast superfluous. Since implicit casts are not allowed anyway (and thankfully) there are no advantages of opCast to artificial method "MyType toMyType();" -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, RussiaHow about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }I find > Class A > { > int opCast(int) { ... } // the opCast operator for casting to int > char opCast(char) { ... } // the opCast operator for casting to char > B opCast(B) { ... } // the opCast operator for casting to B > } more intuitive.
Jul 12 2005
On Wed, 13 Jul 2005 10:41:56 +0400, Victor Nakoryakov <nail-mail mail.ru> wrote:zwang wrote:I'd argue the only time implicit casts would make some sense would be for creating a type that imitates a basic type. Like for example a big integer struct/class, it would benefit from implicit conversion as it would then be interchangable with the basic type it was imitating. As it is in effect externally the same thing as the type it imitates there is no downside or penalty or problem with allowing implicit conversions for it. ReganB Shropshire wrote:I find opCast superfluous. Since implicit casts are not allowed anyway (and thankfully) there are no advantages of opCast to artificial method "MyType toMyType();"How about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }I find > Class A > { > int opCast(int) { ... } // the opCast operator for casting to int > char opCast(char) { ... } // the opCast operator for casting to char > B opCast(B) { ... } // the opCast operator for casting to B > } more intuitive.
Jul 13 2005
Victor Nakoryakov wrote: <snip>I find opCast superfluous. Since implicit casts are not allowed anyway (and thankfully) there are no advantages of opCast to artificial method "MyType toMyType();"Been suggested before. There are lots of different kinds of types - primitives, programmer-defined types, pointers, arrays, functions, delegates ... how would we name the various toType methods? http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/5598 Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jul 13 2005
B Shropshire wrote:How about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }This would indeed be a new syntax. If you're going to do this, why not opt for one that's a bit less redundant? My idea: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/20712 Various ideas: http://www.wikiservice.at/wiki4d/wiki.cgi?FeatureRequestList Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jul 13 2005
B Shropshire Wrote:How about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }rather than have multiple cast use functions like toInt, toChar, toB, for derived types use symbols ex: use toInt_ptr for int* or toInt_ar for int[] or toInt_ar2 for int[2] what is needed is implicit conversions
Jul 20 2007
"Ender KaShae" <astrothayne gmail.com> wrote in message news:f7r8eg$1dnn$1 digitalmars.com... <snip>rather than have multiple cast use functions like toInt, toChar, toB, for derived types use symbols ex: use toInt_ptr for int* or toInt_ar for int[] or toInt_ar2 for int[2]Please see my reply to Victor Nakoryakov on this thread. See also my proposal from a while back: http://tinyurl.com/2uadhz Stewart.
Jul 20 2007
"BCS" <ao pathlink.com> wrote in message news:ce0a3343c0718c998f7f0cf2d1e news.digitalmars.com...Works for me at the moment. Stewart.http://tinyurl.com/2uadhzbad link
Jul 20 2007
Reply to Stewart,"BCS" <ao pathlink.com> wrote in message news:ce0a3343c0718c998f7f0cf2d1e news.digitalmars.com...OK, works now (must be a non D system :)Works for me at the moment. Stewart.http://tinyurl.com/2uadhzbad link
Jul 20 2007
"BCS" <ao pathlink.com> wrote in message news:ce0a3343c0718c998f7f0cf2d1e news.digitalmars.com...Does this one work for you? http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=20712 Stewart.http://tinyurl.com/2uadhzbad link
Jul 20 2007
Reply to Ender,B Shropshire Wrote:?? I don't follow.How about treat the opCast function as if it were a template: Class A { int opCast!(int)() { ... } // the opCast operator for casting to int char opCast!(char)() { ... } // the opCast operator for casting to char B opCast!(B)() { ... } // the opCast operator for casting to B }rather than have multiple cast use functions like toInt, toChar, toB, for derived types use symbols ex: use toInt_ptr for int* or toInt_ar for int[] or toInt_ar2 for int[2] what is needed is implicit conversions
Jul 20 2007