Jump to page: 1 2
Thread overview
Possible syntax for multiple opCast functions
Jul 12, 2005
B Shropshire
Jul 13, 2005
zwang
Jul 13, 2005
Victor Nakoryakov
Jul 13, 2005
Regan Heath
Jul 13, 2005
Stewart Gordon
Jul 13, 2005
Stewart Gordon
Jul 20, 2007
Ender KaShae
Jul 20, 2007
Stewart Gordon
Jul 20, 2007
BCS
Jul 20, 2007
Stewart Gordon
Jul 20, 2007
BCS
Jul 20, 2007
Stewart Gordon
Jul 20, 2007
BCS
July 12, 2005
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
}


July 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
> }
> 
> 

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.
July 13, 2005
zwang wrote:
> 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 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.

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, Russia
July 13, 2005
On Wed, 13 Jul 2005 10:41:56 +0400, Victor Nakoryakov <nail-mail@mail.ru> wrote:
> zwang wrote:
>> 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 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.
>
> I find opCast superfluous. Since implicit casts are not allowed anyway (and thankfully) there are no advantages of opCast to artificial method "MyType toMyType();"

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.

Regan
July 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.
July 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.
July 20, 2007
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
> 

July 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. 

July 20, 2007
Reply to Stewart,

> http://tinyurl.com/2uadhz

bad link


July 20, 2007
"BCS" <ao@pathlink.com> wrote in message news:ce0a3343c0718c998f7f0cf2d1e@news.digitalmars.com...
>> http://tinyurl.com/2uadhz
>
> bad link

Works for me at the moment.

Stewart. 

« First   ‹ Prev
1 2