From -3462315459356275503
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,4ace508b96ee1ef0
X-Google-Attributes: gidf78e5,public
From: "Alexey N. Solofnenko" <trelony@typhoon.spb.ru>
Subject: Re: Who said in C++ there are no functions with different result types and same signatures?
Date: 1998/01/08
Message-ID: <34B1E801.97AF26B9@typhoon.spb.ru>#1/1
X-Deja-AN: 314147106
References: <34B0C280.F532D84A@typhoon.spb.ru> <68rj3h$7s5$3@news.belwue.de>
X-Original-Date: Tue, 06 Jan 1998 11:14:57 +0300
Content-Type: multipart/mixed; boundary="------------279A7784713491A5CB564905"
Organization: Typhoon Software, Inc.
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNLVyeky4NqrwXLNJAQGwEwH/egS2fSD89/zRM6vhMnD4Wsos2TvfCaxh pAM2bmdWt5rg7ok/5LNUay8q5s5W7bJztdWgtnwU5rIIfLZLJnOSkg== =SFi5
Reply-To: trelony@typhoon.spb.ru
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


This is a multi-part message in MIME format.
--------------279A7784713491A5CB564905
Content-Type: text/plain; charset=koi8-r
Content-Transfer-Encoding: 7bit

Hi, Dietmar!

  I always thought that it is prohibited to write template parameterized with return type. I
have CD2 on my hard drive but I did not really read it (I will). But in your example you  wrote
result type explicitly and I tried to avoid it. That is the matter. C creators trusted
programmers (maybe too much). C++ committee does not. I want to be able to say to compiler "Yes,
these functions differ only with result types and that is what I want.", but I can not. The
programmer knows what he is doing.

Best wishes,
  Alexey.




Dietmar Kuehl wrote:

> Hi,
> Alexey N. Solofnenko (trelony@typhoon.spb.ru) wrote:
> :   Don't say I am wrong, there are no such functions. I know it
> : (and don't like it). But there is one exception - casting operators.
> : It can help us to write something which will look like several
> : functions with different result types.
>
> [example snipped]
>
> Actually, there is another method which produces something similar:
> explicit template argument for member template functions:
>
>   class foo
>   {
>   public:
>     ...
>     template <typename T> T bar();
>     template <> T1 bar<T1>() { do_something1; }
>     template <> T2 bar<T2>() { do_something2; }
>   };
>
> At least I think it should work: the later two declarations should be
> specializations of the first one. However, I have no compiler which
> compiles this code... But egcs compiles at least this one:
>
>   #include <iostream.h>
>
>   template <typename T> struct foobar;
>   template <> struct foobar<long> { static long bar() { return 17; } };
>   template <> struct foobar<int>  { static int  bar() { return 13; } };
>
>   template <typename T> T bar() { return foobar<T>::bar(); }
>
>   int main()
>   {
>     cout << bar<int>()  << endl;
>     cout << bar<long>() << endl;
>     return 0;
>   }
>
> ... and produces the expected result :-)
> --
> <mailto:dietmar.kuehl@claas-solutions.de>
> <http://www.informatik.uni-konstanz.de/~kuehl/>
> I am a realistic optimist - that's why I appear to be slightly pessimistic
> ---
> [ 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         ]
> [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
> [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
> [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]



--------------279A7784713491A5CB564905
Content-Type: text/x-vcard; charset=koi8-r; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Alexey N. Solofnenko
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Alexey N. Solofnenko
n:              Solofnenko;Alexey N.
org:            Typhoon Software, Inc.
adr:            ;;;St. Petersburg;;;Russia
email;internet: trelony@typhoon.spb.ru
title:          programmer
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


--------------279A7784713491A5CB564905--
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



