Re: class containing a list of itself

From: Rob Williscroft (rtw_at_freenet.co.uk)
Date: 08/25/04


Date: 25 Aug 2004 14:34:22 GMT

Sharad Kala wrote in news:2p3lcbFfv27rU1@uni-berlin.de in comp.lang.c++:

>> But your code will
>> be non-standard until/unless the standard gets changed.

With hindsight I should have possibly been clearer that the requirment
for completeness of argument types, is only for instantiation *not*
for declaration:

#include <list>

struct X;

extern std::list< X > xlist;

struct X {};

std::list< X > xlist;

>
> I think Standard does mention about this in Section 14.3.1/2
> " ...[Note: a template type argument may be an incomplete type. ] "
>

14.3.1 == Templates / Template type arguments.

Not really relevent to wether or not std::list< T > can take
an incomplete T and be instantiated *before* T is complete.

IOW: you can always (*) declare a specialization which has an incomplete
argument type, what is dependant on the template defenition is wether
you can instantiate such a specialization.

*) Unless such a declaration requires instantition of an
   un-instantiatable specialization:

   template < typename > struct empty {};

   template < typename T, typename U = typename empty< T >::type >
   struct no
   {
   };

   extern no< int > nope;

Rob.

-- 
http://www.victim-prime.dsl.pipex.com/


Relevant Pages

  • Re: Unmanaged Possibilities
    ... is that you can instantiate generic types yourself using reflection. ... generates a new class at compile time. ... A major difference between struct and classes with respect to generics is ... The type instantiation is just like JIT compilation. ...
    (borland.public.delphi.non-technical)
  • Re: OT: Open Source, In The News
    ... it's not the typedef itself that is a problem. ... And only for pointers; if the struct is used in its entirety (passed by ... instantiation, so it reduces the temptation to use typedefs, and I don't ...
    (comp.unix.solaris)
  • Re: struct type completion
    ... # content is an incomplete type. ... We need to re-declare the identifiers to complete their type. ... With struct types this is a bit different: ... declaration, that's why sizeof object is okay after the second ...
    (comp.lang.c)
  • Re: implementing roles in OOP......
    ... > relationship instantiation from relationship navigation. ... > It's not an interface issue; ... > The Client provides the Visitor reference when it invokes ... autognerate the declaration for me. ...
    (comp.object)
  • Re: Using default value of a generic in VHDL
    ... instantiation. ... component declaration inside the architecture that instantiated it, ... I would put it in a package that is in the same physical file as the ... I now have my interface using records, which means I don't have as ...
    (comp.lang.vhdl)