Results 1 to 4 of 4

Thread: Syntax: typedef typename F:: template

  1. #1
    Join Date
    Jun 2009
    Posts
    3,960

    Syntax: typedef typename F:: template

    Code:
    template <class F, class X>
    struct twice
    {
        typedef typename F::template apply<X>::type once;    // f(x) 
        typedef typename F::template apply<once>::type type; // f(f(x)) 
    };
    What is F:: template?

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Syntax: typedef typename F:: template

    Its when "apply" is a meta-function of the class defined by F.

    We will have a tendency to write F::apply, but the syntax is F::template apply

    There is a brief explanation here: http://www.boost.org/doc/libs/1_40_0...her-order.html

  3. #3
    Join Date
    Jun 2009
    Posts
    3,960

    Re: Syntax: typedef typename F:: template

    Metaproduction function? Can you give me an example of code that apply

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Syntax: typedef typename F:: template

    A meta-function is a function that applies to types. For example, you can define the meta-function AddPointer which skips the type int at "int*" like this:

    Code:
    struct AddPointer {
        template<typename T>
        struct apply {
            typedef T* type;
        };
    };
    int main() {
        typedef AddPointer::apply<int>::type TPInt;
        // And here TPInt is a pointer to int... 
        return 0;
    }
    Once in your sample before you took your arguments in a meta-function and a type to which you apply your meta-function. So you use it like this:

    Code:
    int main() {
        AddPointer::apply<int>::type TPInt;
        // and here TPInt is a pointer to int... 
        twice<AddPointer, int>::type TDPInt;
        return 0;
    }
    So the syntax is that when you want to call a structure in a generic type F, you do F:: template apply (apply with your structure is in F). To access IT F:: apply

Similar Threads

  1. Replies: 2
    Last Post: 28-01-2012, 03:50 PM
  2. Difference between Macros and typedef
    By Mithun Seth in forum Software Development
    Replies: 6
    Last Post: 18-01-2010, 02:55 PM
  3. How to create a template of template
    By Harmony60 in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 05:17 PM
  4. Syntax/Semantics for a C++ "Function Template"?
    By Juan-Carlos in forum Software Development
    Replies: 3
    Last Post: 11-11-2009, 06:44 PM
  5. Syntax for SQL query in JSP.
    By elldeegee in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 10:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,811,522.13865 seconds with 16 queries