Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Variadic Templates are Funadic

Download

Right click “Save as…”

Slides

Variadic templates are arguably the most profound change in the core language brought about by C++11. Curiously, however, the C++ community still tiptoes carefully around them: variadic templates enjoyed less coverage than features such as "auto" or lambdas. Part of the reason is that more popular features simplify expression of existing designs, which makes said features easier to understand and use.

Variadic templates, however, not only simplify design and use of advanced libraries such as Boost MPL, but also enable a host of new uses.

This talk provides a solid coverage of variadic fundamentals, including typelists, the archetypal "safe printf" mechanics, and tuple construction and access. It also discusses more advanced uses, such as structured argument lists.

Follow the Discussion

  • AnubisAnubis

    I missed the talk , How do I watch it now?. For god sake upload the talk?

  • Ryan MoldenRyan Molden

    I believe they said that preparing the videos of the talks takes about a day, so I would expect to see any not yet uploaded talks at the beginning of next week. It was a great talk, no Chutuloid-template-horror as one Twitter user was fearing :)

  • I was watching the day 1 big video of this and boom failure.

    When i refreshed the page the day 2 video was in its place Perplexed

    So not where can i get hold of day 1 video ?

  • chethanchethan

    Video please!

  • someonesomeone

    where's the video? It has been more than 24 hours...

  • ChrisChris

    I would not expect video will be today, probably it will be at Monday.
    I'm also looking forward to see it.
    Hopefully tomorrow morning video will be available.

  • savagesavage

    Video, video, video.

  • VenVen

    Video please

  • Andrei Alexandrescuandrei_alex​andrescu Andrei Alexandrescu

    I got word that the video is in processing and will come out later today. Thanks for your interest!

  • CharlesCharles Welcome Change

    Update: It's still encoding (step 5 of 6)... Then, there will be the time it takes to copy all the files to the C9 cloud (this is more a physics problem that can't be solved using template metaprogramming). Fear not. You'll get to see and hear from Andrei soon! In the meantime, I encourage you to eat plenty of blueberries and some fatty fish (omega 3/5 rich) to encourage and accelerate the growth of brain cells. You'll need plenty of them to get the most out of this talk. That's a good thing Smiley

    C

  • CharlesCharles Welcome Change

    Live! Well, on demand! Smiley

    C

  • Xeoc9xeo Sanity is just a mask

    At 00:19:48, I'm pretty sure there's a mistake on the slide.

    template <
        typename T,
        template <
            template<class...> class... Policies
        >
    >
    class ICantBelieveItsNotButter;

    Either a missing "class Name" or the "template< >" around the policies is too much. So much for "My code has no mistakes". Wink

    Other than that, great talk. Enjoyed it very much. Though one thing I'd certainly like to see from the standard side is better (read: smarter) pack expansion, so we don't need to resort to recursion all that often if the expansion is actually really trivial (say, + instead of a comma):

    template<class T, class Head, class... Operands>
    struct var_add{
      static T const value = Head::value + Operands::value...
      //                     pattern -- (                 )
    };

    Whereas the recursive (and current) way would look something like this:

    template<class T, class Head, class... Tail>
    struct var_add{
      static T const value = Head::value + var_add<Tail...>::value;
    };
    
    template<class T, class Head>
    struct var_add<T, Head>{
      static T const value = Head::value;
    };

    (I hope the formatting works...)

  • Andrei Alexandrescuandrei_alex​andrescu Andrei Alexandrescu

    @c9xeo: Actually the code is correct as is. Similarly, when you define a function that takes a pointer to a function you don't need to specify names for the inner parameters:

        void fun(void (*pFun)(int xyz));

    is the same as

        void fun(void (*pFun)(int));

  • Xeoc9xeo Sanity is just a mask

    @Andrei: But then it's still missing a "class" after the "template< >" around the Policies, or am I missing something?

  • Andrei Alexandrescuandrei_alex​andrescu Andrei Alexandrescu

    @c9xeo: Apologies, you're right; I tried to simplify from a larger example I gave at C++ and Beyond and ended up bloating myself. The correct code is:

    template <
      typename T,
      template<class...> class... Policies
    >
    class ICantBelieveItsNotButter;
    

    Thanks for the correction!

  • zbiggzbigg

    Hi,

    on slide 9, (11:46) there is:

    func(5,vs)... func(5,v1),...,func(5,vn)

    In fact i can't find it in standard ([temp.variadic], 14.5.3)
    And more it doesn't work with one of compilers claiming support for (at this time) C++0x variadic templates).

    Can anyone comment ? Is that really in standard ?

  • EnnoEnno

    @zbigg

    The table on the slide is devided by an (invisible) vertical bar between the "Use" and "Expansion" column, namely (in this line) between "func(5, vs)..." and "func(5,v1), ..., func(5, vn)".
    The left part is the actual code, the right side the expansion it stands for.
    As Andrei lovely described, there is a _major_ visual (see the shape of the dots: circles vs. squares) and semantic difference between the ellipses (= "...") on the left and on the right. The left "..." is the actual C++11 pack operator and the right dots present the logical "imagine how this sequence continues"-operator instantiated in your head!
    So suppose your value list vs contains the values v1,v2,v3 then "func(5, vs)..." expands to "func(5, v1), func(5, v2), func(5, v3)"!
    Is this what you meant?

  • Dear C9 Team,

    Since conferences always seem to bring a lot of "where's the video" comments, could you add some sort of status indicator on these posts?  Something like:

    • Talk has not happened yet
    • Talks is airing live
    • Talk is past and was recorded, is now in processing (ideally with an ETA, but you can only do so much)
    • Talk uploaded for perpetual on-demand access by Niners Smiley
  • @zbigg:

    That pack expansion occurs when it is an argument of another function that you are calling (see Slide 8/34 where the pack expansion of Ts and vs occurs on std::forward when calling the gun function).

    Here's another example:

    #include <iostream>
    
    template < typename TYPE >
    inline TYPE g ( TYPE value ) {
        return value;
    }
    
    inline void f () {
        //
    }
    
    template < typename HEAD_TYPE, typename ... TAIL_TYPE_PACK >
    inline void f ( HEAD_TYPE head_value, TAIL_TYPE_PACK ... tail_value_pack ) {
        std::cout << head_value << '\n';
        f( g( tail_value_pack ) ... );
    }
    
    int main () {
         f( 1.0, "2", 3, "four" );
        return 0;
    }

    The code (I believe) you are interested in is the line ...

    f( g( tail_value_pack ) ... );
    ... in the templated f function.  The first time through the templated f function, you could think of the tail_value_pack as being { "2", 3, "four" } and the f( g( tail_value_pack ) ... ) call as expanding to
    f( g( "2" ), g( 3 ), g( "four" ) );
    .  Similarly for the recursive-looking overloaded calls to the templated f function.  Once the tail_value_pack is empty, then you could think of the tail_value_pack as being { } and the f( g( tail_value_pack ) ... ) call as expanding to
    f(  );
    ... hence, the empty regular f function before the templated f function in the code above.

    Using MinGW's g++ version 4.6.2, you can compile and run this using:

    g++ -o main.exe -std=c++0x -march=native -O3 -Wall -Wextra -Werror main.cpp && ./main.exe

    The following is the output of the code above:
    1
    2
    3
    four

    I believe this is covered in section 14.5.3 point 5 ... it seems to be listed in the exampe as:

    f(const_cast<const Args*>(&args)...); // OK: “Args” and “args” are expanded
    .  I don't have the ISO standard, but this was page 346 of N3291 (released April 5th of 2011).

    Hope This Helps,
    Joshua Burkholder

  • CharlesCharles Welcome Change

    , Lars Kemmann wrote

    Dear C9 Team,

    Since conferences always seem to bring a lot of "where's the video" comments, could you add some sort of status indicator on these posts?  Something like:

    • Talk has not happened yet
    • Talks is airing live
    • Talk is past and was recorded, is now in processing (ideally with an ETA, but you can only do so much)
    • Talk uploaded for perpetual on-demand access by Niners Smiley

    Good idea!

  • Simon DanSimon Dan

    Hope that the next version of the Visual studio can invoke this.

  • Andrei write a god-damn book.

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.