Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 12240 invoked from network); 8 Mar 2007 05:09:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Mar 2007 05:09:48 -0000 Received: (qmail 15949 invoked by uid 500); 8 Mar 2007 05:09:56 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 15939 invoked by uid 500); 8 Mar 2007 05:09:56 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 15928 invoked by uid 99); 8 Mar 2007 05:09:56 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2007 21:09:56 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [216.148.227.154] (HELO rwcrmhc14.comcast.net) (216.148.227.154) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Mar 2007 21:09:47 -0800 Received: from [127.0.0.1] (c-67-176-53-28.hsd1.co.comcast.net[67.176.53.28]) by comcast.net (rwcrmhc14) with ESMTP id <20070308050925m1400fuarhe>; Thu, 8 Mar 2007 05:09:25 +0000 Message-ID: <45EF9A5C.3020506@roguewave.com> Date: Wed, 07 Mar 2007 22:08:44 -0700 From: Martin Sebor User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.2pre) Gecko/20070111 SeaMonkey/1.1 MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: [PATCH] dynatype.cpp References: <7BDB2168BEAEF14C98F1901FD2DE64384E1E0F@epmsa009.minsk.epam.com> In-Reply-To: <7BDB2168BEAEF14C98F1901FD2DE64384E1E0F@epmsa009.minsk.epam.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Farid Zaripov wrote: > Below is a patch of dynatype.cpp example to get compiled on MSVC. > > ChangeLog: > * dynatype.cpp: protortype dynatype::remove > > changed to dynatype::remove; > protortype dynatype::copy > changed to > dynatype::copy; > removed dynatype::operator= >; > added code to get compiled on MSVC > > =========================================== > Index: dynatype.cpp > =================================================================== > --- dynatype.cpp (revision 515614) > +++ dynatype.cpp (working copy) > @@ -2,7 +2,7 @@ > * > * dynatype.cpp - Example program of map. See Class Reference Section > * > - * $Id: //stdlib/dev/examples/stdlib/tutorial/dynatype.cpp#11 $ > + * $Id$ > * > > ************************************************************************ > *** > * > @@ -105,27 +105,19 @@ > > // 14.7.3, p6 - explicit specializations must be defined before first > use > template <> > -inline void dynatype::remove >() > +inline void dynatype::remove() The replacement doesn't look equivalent to the original. Is it correct for compilers other than MSVC? > { /* no-op */ } > > > template <> > -inline void dynatype::copy >(const dynatype&) > +inline void dynatype::copy(const dynatype&) > { /* no-op */ } > > > -template <> > -inline dynatype& dynatype::operator= (const dynatype::map&) > -{ > - // no-op > - return *this; > -} > - > - > // initialize with pointers to no-ops > inline dynatype::dynatype () > - : p_remove (&dynatype::remove >), > - p_copy (&dynatype::copy >) > + : p_remove (&dynatype::remove), > + p_copy (&dynatype::copy) > { > } > > @@ -176,8 +168,30 @@ > } > > > +#if defined (_MSC_VER) && (_MSC_VER <= 1310) The examples should be portable C++, i.e., free of #ifdef's and other platform-specific workarounds. Unless there's a way to get it to work with the compiler I'm not sure we should pollute the code with hacks for broken compilers. Btw., do you have a test case for the MSVC bug that prevents the code from compiling? Martin > + > +// to avoid MSVC 7.1 error LNK2019: unresolved external symbol > +static inline void foo () > +{ > + dynatype dt; > + int &i = dt; > + double &d = dt; > + const char *&p = dt; > + char &c = dt; > +} > + > +#endif // (_MSC_VER) && (_MSC_VER <= 1310) > + > + > int main () > { > + // avoid error C2440 on MSVC > +#ifdef _MSC_VER > +#define CREF(x) const_cast(x) > +#else > +#define CREF(x) x > +#endif > + > try { > std::cout << "dynatype v1 = 1\n"; > > @@ -185,32 +199,32 @@ > dynatype v1 = 1; > > std::cout << "int (v1) = " > - << int (v1) << std::endl; > + << int (CREF (v1)) << std::endl; > > // assign a double to an instance of dynatype > v1 = 3.14; > > std::cout << "double (v1 = 3.14) = " > - << double (v1) << std::endl; > + << double (CREF (v1)) << std::endl; > > // copy construct an instance of dynatype > dynatype v2 = v1; > > std::cout << "double (v2 = v1) = " > - << double (v2) << std::endl; > + << double (CREF (v2)) << std::endl; > > // assign a const char* literal to an instance of dynatype > const char* const literal = "abc"; > v2 = literal; > > std::cout << "(const char*)(v2 = \"abc\") = " > - << (const char*)v2 << std::endl; > + << (const char*)CREF (v2) << std::endl; > > // assign one instance of dynatype to another > v1 = v2; > > std::cout << "(const char*)(v1 = v2) = " > - << (const char*)v1 << std::endl; > + << (const char*)CREF (v1) << std::endl; > > // create uninitialized (untyped) instances of dynatype > dynatype v3, v4; > @@ -220,7 +234,7 @@ > > // attempt to extract any value from an unitialized dynatype > fails > std::cout << "char (v3) = " > - << char (v1) << std::endl; > + << char (CREF (v3)) << std::endl; > > } > catch (...) { > =========================================== > > Farid. > >