Topic: Template classes in C++0x


Author: "Vidar Hasfjord" <vattilah-groups@yahoo.co.uk>
Date: Fri, 13 Apr 2007 09:04:32 CST
Raw View
On Apr 12, 12:08 am, REkalleMOunderscoreVErutane...@hotmail.com (Kaba)
wrote:
> There clearly is redundancy here. It would be beneficial to group the
> definitions to blocks which defines the surrounding class. I know there
> has been a proposal to do just this, but I can't quite find it in the
> current proposal list.

You may be thinking of Carl Daniel's proposal, "Proposed Addition to C+
+: Class Namespaces", N1440.

> This is of course something that everyone
> here has experience from, but is this problem currently going to be
> addressed?

I don't think so; at least not in C++09. The proposal is currently
categorized as "No active interest today, but open to resubmit in
future" in the latest "State of C++ Evolution" document (N2169).

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: REkalleMOunderscoreVErutanenME@hotmail.com (Kaba)
Date: Fri, 13 Apr 2007 17:11:07 GMT
Raw View
> You may be thinking of Carl Daniel's proposal, "Proposed Addition to C+
> +: Class Namespaces", N1440.

Yes. Although by clicking the link in the "State of C++ Evolution"
directs you to "C++ Standard Library Active Issues List".

> > This is of course something that everyone
> > here has experience from, but is this problem currently going to be
> > addressed?
>
> I don't think so; at least not in C++09. The proposal is currently
> categorized as "No active interest today, but open to resubmit in
> future" in the latest "State of C++ Evolution" document (N2169).

Well that's unexpected. Because it is only a new notation, it should not
have any effects to other parts of C++ and thus should be trivial to
implement. The reductions on redundant code would be great in some
cases. I see only positive effects, why was it rejected?

--
Kalle Rutanen
http://kaba.hilvi.org

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: "James Kanze" <james.kanze@gmail.com>
Date: Fri, 13 Apr 2007 12:33:07 CST
Raw View
On Apr 12, 6:41 am, "Mathias Gaunard" <loufo...@gmail.com> wrote:
> On Apr 12, 1:08 am, REkalleMOunderscoreVErutane...@hotmail.com (Kaba)
> wrote:

> > Consider a template class that has lots of parameters:

> > template <typename C1, typename C2, typename C3, etc>
> > class A
> > {
> > public:
> > void f();
> > voif g();
> > };

> > Now defining the member functions outside of A, f and g require lots of
> > code to specify the class around them:

> What's the point of defining them outside of A since all your code
> will have to be in headers anyway?

First, of course, with a compliant compiler, the code won't have
to be in the headers.  And even without a compilant compiler,
readability concerns will probably mean that you want to define
the functions later, and maintainability concerns will probably
mean that you'll define them in a separate file, even if that
file ultimately gets included by your header.

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: jdennett@acm.org (James Dennett)
Date: Fri, 13 Apr 2007 22:02:43 GMT
Raw View
Kaba wrote:
>> You may be thinking of Carl Daniel's proposal, "Proposed Addition to C+
>> +: Class Namespaces", N1440.
>
> Yes. Although by clicking the link in the "State of C++ Evolution"
> directs you to "C++ Standard Library Active Issues List".
>
>>> This is of course something that everyone
>>> here has experience from, but is this problem currently going to be
>>> addressed?
>> I don't think so; at least not in C++09. The proposal is currently
>> categorized as "No active interest today, but open to resubmit in
>> future" in the latest "State of C++ Evolution" document (N2169).
>
> Well that's unexpected. Because it is only a new notation, it should not
> have any effects to other parts of C++ and thus should be trivial to
> implement. The reductions on redundant code would be great in some
> cases. I see only positive effects, why was it rejected?

I don't know about rejected, but the most likely reason
for it to be stalled is that nobody has volunteered to
do the work of taking it from a proposal to having
formal wording and a proof-of-concept implementation.
This just means that those who have volunteered their
time and expertise felt that there were more important
things to be working on.  If someone additional
volunteers to do the work and champion this proposal,
it could get unstalled -- but it's rather late now to
expect it to make it into C++09.

-- James

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: REkalleMOunderscoreVErutanenME@hotmail.com (Kaba)
Date: Wed, 11 Apr 2007 23:08:22 GMT
Raw View
Consider a template class that has lots of parameters:

template <typename C1, typename C2, typename C3, etc>
class A
{
public:
void f();
voif g();
};

Now defining the member functions outside of A, f and g require lots of
code to specify the class around them:

template <typename C1, typename C2, typename C3, etc>
void A<C1, C2, C3, etc>::f()
{
}

template <typename C1, typename C2, typename C3, etc>
void A<C1, C2, C3, etc>::g()
{
}

There clearly is redundancy here. It would be beneficial to group the
definitions to blocks which defines the surrounding class. I know there
has been a proposal to do just this, but I can't quite find it in the
current proposal list. Now I'm concerned if there is no proposal to
reduce this template boiler-plate. Sometimes that boiler-plate can take
a huge portion of the text of the file and really makes the code hard to
read and frustrating to write. This is of course something that everyone
here has experience from, but is this problem currently going to be
addressed?

--
Kalle Rutanen
http://kaba.hilvi.org

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: "Mathias Gaunard" <loufoque@gmail.com>
Date: Wed, 11 Apr 2007 22:41:17 CST
Raw View
On Apr 12, 1:08 am, REkalleMOunderscoreVErutane...@hotmail.com (Kaba)
wrote:
> Consider a template class that has lots of parameters:
>
> template <typename C1, typename C2, typename C3, etc>
> class A
> {
> public:
> void f();
> voif g();
>
> };
>
> Now defining the member functions outside of A, f and g require lots of
> code to specify the class around them:

What's the point of defining them outside of A since all your code
will have to be in headers anyway?

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: REkalleMOunderscoreVErutanenME@hotmail.com (Kaba)
Date: Thu, 12 Apr 2007 13:46:49 GMT
Raw View
> What's the point of defining them outside of A since all your code
> will have to be in headers anyway?

Style. That way I am (and everyone else reading my code are) able to see
the class interface without distracting information. To make this even
more explicit, I have a habit to do something like this:

a.h:

#ifndef A_H
#define A_H

template <typename Type>
class A
{
public
   void f();
};

#include "a.hpp"

#endif

a.hpp:

#ifndef A_HPP
#define A_HPP

#include "a.h"

template <typename Type>
void A<Type>::f()
{
}

#endif

That is very similar to what you do with normal classes.

--
Kalle Rutanen
http://kaba.hilvi.org

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: AlbertoBarbati@libero.it (Alberto Ganesh Barbati)
Date: Thu, 12 Apr 2007 14:31:09 GMT
Raw View
Kaba ha scritto:
> Consider a template class that has lots of parameters:

The term "template class" has been around for some time, but has been
deprecated since C++03 because it's imprecise. According to English
grammar rules, a "template class" should be a "class", but people keep
using the term to refer to a "template of classes", incorrectly.

The correct term is "class template".

HTH,

Ganesh

PS: the term "template class" should actually be a synonym of
"instantiation of a class template" (which, in fact, is a class).
However I personally prefer to avoid the term altogether because there's
a risk of misunderstanding.

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: Nicolas Pavlidis <aon.912719634@aon.at>
Date: Thu, 12 Apr 2007 09:35:14 CST
Raw View
Mathias Gaunard wrote:
> On Apr 12, 1:08 am, REkalleMOunderscoreVErutane...@hotmail.com (Kaba)
> wrote:
>> Consider a template class that has lots of parameters:
>>
>> template <typename C1, typename C2, typename C3, etc>
>> class A
>> {
>> public:
>> void f();
>> voif g();
>>
>> };
>>
>> Now defining the member functions outside of A, f and g require lots of
>> code to specify the class around them:
>
> What's the point of defining them outside of A since all your code
> will have to be in headers anyway?

I think, he menas something like that:

// the header
template<typename Type>
class MyClass
{
//....
};

#include "MyClass.tcpp"

This approach has the advantage that the declaration are sperated from
the definition, and that you can compile the template class, searching
for obious errors (I know that every method of a template - class needs
to be instanziated to find all syntactic erros, but some obious ones can
be found that way too).

The Problem is, that some compilers really want all the code belonging
to a template inside the class - declaration.

For short, this is a (unfortunately not portable) way to have a little
bit of sourcode organisation with templates.

Best regards,
Nicolas

P.S.: I hope I didin't misunderstand your question :-).

> ---
> [ 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.comeaucomputing.com/csc/faq.html                      ]
>

---
[ 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.comeaucomputing.com/csc/faq.html                      ]