From 5873296373723706742
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 109fba,9aa486e5a5fcf1c1
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,bfc25674b1a4166f
X-Google-Attributes: gidf78e5,public
From: =?ISO-8859-1?Q?J=F6rg?= Barfurth <joerg.barfurth@attglobal.net>
Subject: Re: templated Copy-Constructor?
Date: 2000/04/29
Message-ID: <20000428.16141329@jb-11116.stardiv.de>#1/1
X-Deja-AN: 616840795
Content-Transfer-Encoding: quoted-printable
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
References: <39099e33$0$22977@businessnews.de.uu.net>
X-Priority: 3 (Normal)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Content-Type: text/plain; charset=ISO-8859-1
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Trace: mail2news.demon.co.uk 956939742 mail2news:23335 mail2news mail2news.demon.co.uk
Organization: Sun Microsystems Inc. / Star Office Entwicklungs GmbH, Hamburg, Germany
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Mime-Version: 1.0
Reply-To: joerg.barfurth@attglobal.net
X-MIME-Autoconverted: from 8bit to quoted-printable by mulga.cs.mu.OZ.AU id CAA27473
Newsgroups: comp.lang.c++,comp.std.c++

Am 29.04.00, 02:41:36, schrieb "Stephan Keil" <kei@parsytec.de> zum Thema=
=20
templated Copy-Constructor?:


> Hi,

> consider the following example:

>  template<class T>
>  struct Blah
>  {
>   Blah(){}

>   template<class U>
>   Blah(const Blah<U>&)
>   {
>    cout << "Blah" << endl;
>   }
>  };

>  Blah<double> bd(Blah<int>());
>  Blah<int> bi(Blah<int>());

> With VC++ 6.0 the construction of 'bd' invokes the templated
> constructor where as the construction of 'bi' does not
> (i.e. apparently the compiler generated copy constructor
> is used instead). Is this correct behaviour according to
> the standard?

This is correct. The standard explicitly says that template constructors=20
(and assignment operators) wont be considered for copy construction (or=20
assignment).

Basically, the compiler-generated declarations are suppressed only if you=
=20
declare a non-template copy constructor (or assignment operator).

But then the (non-template) implicitly-declared overload takes precedence=
=20
over any matching template specializations.

Some more motivation: Otherwise the compiler, when seeing ...

template <class> struct Blah;
template <class T, class U> struct BlahDef;

template <class T>
struct Blah
{
	template <class U> Blah(Blah<U> const&);
	template <class U> Blah(U);

	template <class U> struct rebind { typedef Blah<U> other; }
	template <class U> Blah(typename rebind<U>::other const&);
	template <class U> Blah(typename Blah<U>::rebind<T>::other const&);

	template <class U> Blah(typename BlahDef<U, T>::type const&);
};

template <class T, class U> struct BlahDef
{=20
	typedef typename Blah<T>::rebind<U>::other type;
	// or simply: typedef T type;
};

... would have to try to find template arguments to instantiate a copy=20
constructor from the templates, in order to find out whether to=20
implicitly declare a copy constructor. Even restricting this to contexts=20
where the template arguments are deducible doesn't really improve the=20
situations.

As the standard is those template declarations might never be=20
instantiated.

> thanks for comments,

> Stephan

HTH

-- J=F6rg


---
[ 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              ]




