75e5cab1   
   From: daniel.kruegler@googlemail.com   
      
   Am 20.06.2011 21:15, schrieb Arne Mertz:   
   >   
   > On 17 Jun., 09:50, Daniel Krügler   
   > wrote:   
      
   [..]   
      
   > I guess I was not very clear in my question. Of course I know that the   
   > constructor is too late. My idea was something like the following:   
   >   
   > template DefaultDestructor> //Note: no explicit Signature parameter   
   > class GenericFactory   
   > {   
   > typedef SINGATURE_OF(DefaultCreator) Signature; //here it is   
   > /* ... */   
   > };   
   >   
   > So the question was: is there some way to implement the "SIGNATURE_OF"   
   > above?   
      
   Let me first start with the remark that your description misses some   
   relevant details, e.g. you never explain what kind of types   
   "CreationSignature" or "DefaultDestructor" are supposed to be. I can   
   only assume, that these are assumed to be a function type. In the   
   following I assume that they are function types because you are feeding   
   boost::function with it.   
      
   The problem is, that there does not exists a *single* type that   
   represents a function signature. Of course you can use some   
   "signature-compression" form, e.g. by using a single function type as   
   the representation of the parameter types, but you cannot "unpack" them   
   within a primary template like GenericFactory to declare a function from   
   this.   
      
   It is possible to realize this with a large amount of work in C++03 by   
   partially specializing GenericFactory, e.g.   
      
   template   
   struct GenericFactory; // Not defined   
      
   template   
   struct GenericFactory {   
      
    R Create();   
    [..]   
   };   
      
   template   
   struct GenericFactory {   
      
    R Create(Arg);   
    [..]   
   };   
      
   Whether this a reasonable approach depends on the number of parameters   
   you need to support. This is the reason, why most C++03 implementations   
   instead add a series of overloads within the class.   
      
   In C++0x this is solvable by defining a single partial specialization   
   due to variadics, but as you say, you cannot use this approach for the   
   moment due to compiler limitations.   
      
   Alternatively you could impose some constraints on the caller, e.g. you   
   could require that the argument is expressed as a single tuple (this   
   works with tr1::tuple and boost::tuple), in this case you would just write:   
      
   template   
   struct Signature; // Not defined   
      
   template   
   struct Signature {   
    typedef R return_type;   
    typedef tuple<> arguments;   
   };   
      
   template   
   struct Signature {   
    typedef R return_type;   
    typedef tuple arguments;   
   };   
      
   // etc...   
      
   template   
   struct GenericFactory {   
    typedef Signature sig;   
    typename sig::return_type Create(typename sig::arguments);   
    [..]   
   };   
      
   This approach is similar to what the /piecewise construction/ idiom in   
   the C++0x std::pair template provides but as mentioned above it means   
   that callers have to obey this special protocol.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|