C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

n1785 - Object Templates concerns

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Maciej Sobczak
Guest





PostPosted: Thu May 19, 2005 8:34 pm    Post subject: n1785 - Object Templates concerns Reply with quote



Hello,

After reading the n1785 (Toward a Proposal for Object Templates in
C++0x) I have some feedback that I would like to share.

The authors of this proposal argue that it would be good to have the
possibility to use objects with static storage duration at namespace
scope that would be "templates" in the sense that we know from classes
and functions.
The example is:

template< class T = double>
T const pi = 3.1415926L;

with possible specializations (for different types), etc.
The idea is to use it in generic code (for example, from the template
function that computes the area of circle), so that it always resolves
to the type that is needed:

template <typename T>
T area_of_circle(T radius)
{
return static_cast<T>(pi) * radius * radius;
}


My feedback is:

I think that the above has no advantage over what we already can do with
the same effect on the "client" side:

struct PiType
{
template <typename T>
operator T() const { return 3.1415926536; }
} pi;

The object "pi" above can be used in generic code (like the
area_of_circle function). Specializations for different types or even
distinguishing reads from writes are possible as well.

Regards,

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
martinfrompi@yahoo.co.uk
Guest





PostPosted: Tue May 24, 2005 9:28 pm    Post subject: Re: n1785 - Object Templates concerns Reply with quote



Maciej Sobczak wrote:
Quote:
struct PiType
{
template operator T() const { return 3.1415926536; }
} pi;

The object "pi" above can be used in generic code (like the
area_of_circle function). Specializations for different types or even

distinguishing reads from writes are possible as well.

The problem is that if *you* (or boost or the standard committee) write
PiType, and *I* write MartinsSuperHighPrecisionType, there is no way
for *me* to add operator MartinsSuperHighPrecisionType() const to
PiType.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Nicola Musatti
Guest





PostPosted: Wed May 25, 2005 3:50 pm    Post subject: Re: n1785 - Object Templates concerns Reply with quote





[email]martinfrompi (AT) yahoo (DOT) co.uk[/email] wrote:
Quote:
Maciej Sobczak wrote:
struct PiType
{
template <typename T
operator T() const { return 3.1415926536; }
} pi;

The object "pi" above can be used in generic code (like the
area_of_circle function). Specializations for different types or even

distinguishing reads from writes are possible as well.

The problem is that if *you* (or boost or the standard committee) write
PiType, and *I* write MartinsSuperHighPrecisionType, there is no way
for *me* to add operator MartinsSuperHighPrecisionType() const to
PiType.

No problem. Just write

template <> PiType::operator MartinsSuperHighPrecisionType() const {
return MartinsSuperHighPrecisionType(3.2);
}

Cheers,
Nicola Musatti

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.