Topic: Can templates produce POD's and/or aggregates?


Author: schnitker@sigma-c.com (Uwe Schnitker)
Date: Wed, 31 Jul 2002 15:02:05 GMT
Raw View
While I don't remember the full requirements for POD's and aggregates,
I know that the following struct satisfies them both:

struct S{
  int i_;
  double d_;
  char * cStr_;
// STUFF
};

if STUFF is empty or contain only declarations of public, nonvirtual
member fuctions, none of which is a destructor or constructor, etc...

Now consider the following:

template<typename First, typename Second, typename Third>
struct TS{
   First  first_;
   Second second_;
   Third  third_;
// STUFF
};

Question: Is TS<int,double,char*>
i)   an aggregate
ii)   a POD
ii)  data-layout-compatible with S
given the same constraints on STUFF?

I assume all answers to be "yes", but I'd like some confirmation.
I never read anything about this, but I have to admit that I
didn't dig very deep into the Standard or the CD.

Regards,
Uwe

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





Author: kanze@gabi-soft.de (James Kanze)
Date: Thu, 1 Aug 2002 15:09:35 GMT
Raw View
schnitker@sigma-c.com (Uwe Schnitker) wrote in message
news:<aec458c5.0207302157.e8d9964@posting.google.com>...
> While I don't remember the full requirements for POD's and aggregates,
> I know that the following struct satisfies them both:

> struct S{
>   int i_;
>   double d_;
>   char * cStr_;
> // STUFF
> };

> if STUFF is empty or contain only declarations of public, nonvirtual
> member fuctions, none of which is a destructor or constructor, etc...

> Now consider the following:

> template<typename First, typename Second, typename Third>
> struct TS{
>    First  first_;
>    Second second_;
>    Third  third_;
> // STUFF
> };

> Question: Is TS<int,double,char*>
> i)   an aggregate
> ii)   a POD
> ii)  data-layout-compatible with S
> given the same constraints on STUFF?

> I assume all answers to be "yes", but I'd like some confirmation.  I
> never read anything about this, but I have to admit that I didn't dig
> very deep into the Standard or the CD.

You don't have to dig very deeply.  Templates don't define a type; they
define a schema for defining a type.  And there is nothing in the
standard which says that a type so generated differs in any way from the
same type declared explicitly.  In your case, TS<int,double,char*> is a
struct, with no access specifiers, etc., etc.  It is, in fact,
indistiguishable from a struct declared directly with the same members,
etc.

--
James Kanze                           mailto:jkanze@caicheuvreux.com
Conseils en informatique orient   e objet/
                    Beratung in objektorientierter Datenverarbeitung

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