From -6266537815745596057
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ede379f5dbbc1549
X-Google-Attributes: gidf78e5,public
From: sbnaran@uiuc.edu (Siemel B. Naran)
Subject: Re: Suggestion: "typeof" keyword
Date: 1999/08/13
Message-ID: <slrn7r5v1a.kn9.sbnaran@localhost.localdomain>#1/1
X-Deja-AN: 512289898
X-NNTP-Posting-Host: jakarta-6.slip.uiuc.edu
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <7nt3vl$1oe$1@nnrp1.deja.com> <7oh7o8$t3f$1@nnrp1.deja.com> <7ol6hi$ej9$2@news.BelWue.DE> <cTiioXAhAwr3Ew$X@robinton.demon.co.uk> <t7d7ww1vrz.fsf@calumny.jyacc.com> <e4DSyfA4ALs3Ew0Q@robinton.demon.co.uk> <t7hfm6ytow.fsf@calumny.jyacc.com>
X-UID: 0000000001
X-Status: $$$T
Organization: University of Illinois at Urbana-Champaign
User-Agent: slrn/0.9.5.7 (UNIX)
Reply-To: sbnaran@uiuc.edu
Newsgroups: comp.std.c++
Originator: clamage@taumet


On 12 Aug 99 14:15:00 GMT, Hyman Rosen <hymie@prolifics.com> wrote:

>If you think about it, there is a fundamental asymmetry in function
>template argument deduction, in that the deduced types are fully
>available to be used within the function, including declaring new
>variables of the deduced types and derivations based on them, but
>there is no way to use such a deduced type *outside* the function.

I find this paragraph puzzling.  Did you mean to say this: deduced
types are available outside the function, but are not available
within the function itself.  With code:
   template <class Thing> silly(Thing t) { ... }
   void f() { silly(std::bind2nd(std::plus<int>(),5)); }
We see that the type of "std::bind2nd(std::plus<int>(),5)" is fully
available to the external function 'silly'.

It would be nice if we didn't have to always call an external
function to take advantage of template argument deduction: it would
be nice if deduced types were available within the function itself.
Then we could say
   void f() { typeof(expr) t(expr); ... }
where 'expr' is "std::bind2nd(std::plus<int>(),5)".  Now we can
use 't' inside the body of the function 'f'.  Without the typeof
keyword I have to figure out the type of 't' myself.  Let me
give it a shot:
   typeof(t)==std::binder2nd<std::plus<int>>
Not so hard.  But what if we had longer expressions using
std::compose, std::mem_fun, and stuff we may write ourselves?

Incidentally, the code
   declare t=std::bind2nd(std::plus<int>(),5);
is very useful.  But to avoid having to create a new keyword we
can do this:
   #define expr=std::bind2nd(std::plus<int>(),5);
   typeof(expr) t=expr;
   #undef expr



>It is this asymmetry which typeof corrects.

Agreed.

-- 
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




