IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Return value problem
you nailed it - how do you tell which type, T1 or T2 should be the return value? And how do you write the code such that the correct precision is maintained in the result?

Answer: you specialize the template - to the point that you've fully specified all possible overload sequences and then the template has shown itself to be worthless in this case (except for the everything-is-a-T case).

you could try this:

template<class T>
double max(double x1, T x2) // if there's one double they're all double
{
return x1 > x2 ? x1 : x2;
}

to save some work - but you'll get an ambiguity if you try max(double, double) between the max is all T's and max T1 T2 definitions.

Thus, C++ can help you expand work to fill all available time with no trouble at all.

Or you could use a macro.



"Packed like lemmings into shiny metal boxes.
Contestants in a suicidal race."
    - Synchronicity II - The Police
Expand Edited by tuberculosis Aug. 21, 2007, 06:33:56 AM EDT
New I'll take a look for the solution for ret value
In the meantime, have a fill of this: a guy at the place where I work uses templates to overload _integers_ with tracking code. He will then use those overloaded integers in the contexts wher he wants to collect stats. For the user, it's still an integer, slightly larger in memory. Stats collector has a thread to get snapshots and remember them.

This struck me as a very Smalltalk-ish thing to do. :)
--

Want to be original? Start with a great template!
New Re: Return value problem
It's interesting - I've done most of my C++ coding in some numerical/mathematical context - needless to say, the occasion to use templates came up again and again - and then I'd think - no, the very fact that I'm thinking about this means these things are enough different to treat differently, and so forget this stupid template.

See, it's not really a template - it's a second, backdoor attempt to have a scalable type of data, since the objectness in the front door effort is a sort of fake.

Finally I'd accomplish making the differences manifest with overloading by hand - which no doubt is all the template is doing in the first place, and the code made much more sense.

-drl
New In the end
you do need different implementations for different types, so "overloading by hand" is inevitable. It's nice to have compiler do it for you.

I agree that templates represent another, backdoor attempt at real type system, after virtual functions failed to deliver. I am beginning to think that templates are simply Smalltalk-style metadata, represented in many, many versions of generated code. Just like in Lisp one can implement lists with closures, the same way one can replace metadata with lots of generated code. To some extent. There have to be better statically-typed languages.
--

Want to be original? Start with a great template!
New A better statically typed language - have you tried Haskell?
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Read the tutorials
it is somewhat related to the ML series IIRC, the most popular being OCAML I think.

There are some interesting ideas in there and I can think of two language research projects that are also working on similar typing ideas - one called slate which is being implemented in squeak, and the needle project.

The thing that keeps me from bothering to write code in languages like these is lack of platform interface support - ie, is there a bridge to most system routines I might want or a reasonably complete library availble. (for instance oberon was touted as being a great oo environment for awhile - but it had its own everything and always looke really ugly and alien on all the platforms I've seen it run on).



"Packed like lemmings into shiny metal boxes.
Contestants in a suicidal race."
    - Synchronicity II - The Police
Expand Edited by tuberculosis Aug. 21, 2007, 12:41:27 PM EDT
New Today's link at /.
An [link|http://www.paulgraham.com/hp.html|article] on "hackers".

>>>>>>>>>>>>>>>>>>>
We need a language that lets us scribble and smudge and smear, not a language where you have to sit with a teacup of types balanced on your knee and make polite conversation with a strict old aunt of a compiler.
<<<<<<<<<<<<<<<<<<<
--

Want to be original? Start with a great template!
     C++ File I/O: Windows vs. Linux - (tjsinclair) - (85)
         Wild guess - (JayMehaffey) - (1)
             Nope - (tjsinclair)
         Permissions problem? - (tuberculosis) - (16)
             Possibly - (tjsinclair) - (15)
                 The only dumb question is... - (jbrabeck) - (14)
                     Thanks - (tjsinclair) - (13)
                         I'd second the permissions... - (jbrabeck) - (12)
                             Played with error bits - (tjsinclair) - (11)
                                 C++ for real work - (tuberculosis) - (10)
                                     telco's use lots of c++ -NT - (boxley) - (7)
                                         on UNIX? - (tjsinclair) - (6)
                                             well several softswitches and other software (added link) - (boxley) - (2)
                                                 Yeah - OS level code I think - (tuberculosis) - (1)
                                                     Stacked based types? - (deSitter)
                                             some more info on c++ Unix and Telcos and jobs - (boxley) - (2)
                                                 CORBA == Objects, so makes sense - (tjsinclair)
                                                 Resume mailed -NT - (tuberculosis)
                                     Someone somewhere must be using it - (tjsinclair)
                                     Network Management software - (Arkadiy)
         I don't know C++ but... - (ben_tilly) - (6)
             Seems like it ought to raise an exception on failure -NT - (tuberculosis) - (5)
                 It does - (tjsinclair) - (4)
                     Erroring out? - (tuberculosis) - (3)
                         I checked the ios error flags - (tjsinclair) - (2)
                             Thats not raising an exception - (tuberculosis) - (1)
                                 Agreed - (tjsinclair)
         Got it! - (tjsinclair) - (58)
             Now, this is really scary - (Arkadiy) - (53)
                 Even scarier - (tjsinclair) - (52)
                     At this point, one wants to,, - (deSitter) - (3)
                         Ross, do we need a refresher... - (jb4) - (2)
                             I would completely agree with you except - (tjsinclair) - (1)
                                 Wow! - (jb4)
                     Which version of gcc? - (admin)
                     So, let me get this straight... - (Arkadiy) - (46)
                         Something like that, yes - (tjsinclair) - (44)
                             I've been trying to do that for years - (tuberculosis)
                             Barney is not responsible... - (jb4) - (42)
                                 Move farther up the food chain - (tuberculosis) - (41)
                                     OK, I'll bite... - (jb4) - (39)
                                         Errr... - (admin) - (34)
                                             I've heard strong typing called several different things... - (jb4) - (33)
                                                 Strict typing is like training wheels. - (admin) - (32)
                                                     Re: Strict typing is like training wheels. Or Helmuts? - (jb4) - (31)
                                                         You have much to learn - (tuberculosis) - (23)
                                                             Irony - (ben_tilly) - (22)
                                                                 Additionally... - (admin) - (21)
                                                                     That's the C++ propaganda - (tuberculosis) - (20)
                                                                         Wrong usage - (Arkadiy) - (7)
                                                                             Return value problem - (tuberculosis) - (6)
                                                                                 I'll take a look for the solution for ret value - (Arkadiy)
                                                                                 Re: Return value problem - (deSitter) - (4)
                                                                                     In the end - (Arkadiy) - (3)
                                                                                         A better statically typed language - have you tried Haskell? -NT - (ben_tilly) - (1)
                                                                                             Read the tutorials - (tuberculosis)
                                                                                         Today's link at /. - (Arkadiy)
                                                                         Interesting example, Todd - (jb4) - (11)
                                                                             Umm... - (Simon_Jester) - (5)
                                                                                 And what would you cast the void* back to afterwards? -NT - (tuberculosis) - (4)
                                                                                     Yeah, you'd have to test for the type... - (Simon_Jester) - (3)
                                                                                         Aaaaaahhhhhhh! - (tuberculosis) - (2)
                                                                                             *chuckle* - (Simon_Jester) - (1)
                                                                                                 Oh, you illustrated several problems - (tuberculosis)
                                                                             Your code should crash - (tuberculosis) - (4)
                                                                                 My code does crash, but not as often as you think. - (jb4) - (3)
                                                                                     Re: My code does crash, but not as often as you think. - (admin) - (1)
                                                                                         Replies coming - (jb4)
                                                                                     Re: My code does crash, but not as often as you think. - (tuberculosis)
                                                         Finally, something other than hand-waving. - (admin) - (6)
                                                             Hey I know Java - (tuberculosis) - (3)
                                                                 Whoops, forgot that one. - (admin) - (2)
                                                                     I always sit on a towel when using it - (tuberculosis) - (1)
                                                                         Interesting... I find I get more use out of... - (admin)
                                                             I've done it - (Arkadiy) - (1)
                                                                 Re: I've done it - (admin)
                                         How? - (tuberculosis) - (3)
                                             Erm? - (jb4) - (2)
                                                 GNU CPP version 2.95.2 19991024 (release) -NT - (tuberculosis) - (1)
                                                     Sorry to hear that...:-( - (jb4)
                                     Well said, exactly correct -NT - (deSitter)
                         This is frigging runtime lib bug, not language - (Arkadiy)
             You were mis-using the flags... - (Simon_Jester) - (3)
                 I thought of that - (tjsinclair) - (2)
                     For what it's worth, code also runs... - (a6l6e6x) - (1)
                         Figured that -NT - (tjsinclair)

Yeah, would be nice if "despair" wasn't such an appropriate word choice.
118 ms