POV-Ray : Newsgroups : povray.off-topic : C++ templates to get Java-style interfaces... : Re: C++ templates to get Java-style interfaces... Server Time
11 Oct 2024 09:20:16 EDT (-0400)
  Re: C++ templates to get Java-style interfaces...  
From: Warp
Date: 20 Oct 2007 06:32:59
Message: <4719d95b@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> http://permalink.gmane.org/gmane.comp.lib.boost.devel/166593

> As illustrated by a stupid example.  Or at least overly-simplistic 
> example. I mean, really, if your compiler can't generate the best code 
> for (x + x) where x is an integer, do you really want to take the time 
> to teach the compiler to do so? :-)

  I don't have the slightest clue what the subject of your post has to do
with that article.

  Anyways, the idea of concepts in the new C++ standard is not related to
code generation at all. It's simply related to getting clearer error
messages when using templates.

  One problem with current templates is that template functions implicitly
expect the template type to have certain properties. There's no way to
*explicitly* tell that the template expects, for example, that the given
type supports the operator +, or the operator =, or the functions begin()
and end(), for example. The only way to "tell" it is to simply use them
in the function implementation.
  The problem with this is that if you give some type not meeting those
requirements to the template, the error message will usually be very
cryptic because it will be spawned from somewhere inside the template
function. The problem is worsened by the fact that many template classes
and functions (especially in the standard library) have many template
parameters (some of them with default values), making the error message
longer and more cryptic.

  The idea with concepts is that you can create specify explicitly in the
declaration of a template function all the requirements for the template
type. For example, you can explicitly say "the type requires operator +,
operator = and the member functions begin() and end()". If the user then
calls the template function with a type which does not meet those
requirements, the compiler can then give a very clear and explicit error
message, like "this template parameter requires operator +, but the type
you gave at this line doesn't support it".

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.