Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:56:26+00:00 2026-05-31T05:56:26+00:00

Andrei Alexandrescu gave an excellent talk entitled: Variadic Templates are Funadic . He presents

  • 0

Andrei Alexandrescu gave an excellent talk entitled: Variadic Templates are Funadic.

He presents the following 3 expansions which are subltey different:

template <class... Ts> void fun( Ts... vs ) {
    gun( A<Ts...>::hun(vs)...);
    gun( A<Ts...>::hun(vs...));
    gun( A<Ts>::hun(vs)...);
}

He explains:

Call 1:
Expands all Ts for instatiation of class A,
Then calls hun(vs)
Then expands all parameters again when passing them into gun

Call 2:
Expands all Ts and all vs separately

Call 3:
Expnads in lock step, ie:
Expand argument 1 of Ts and Argument 1 of vs
Expand argument 2 of Ts and Argument 2 of vs
Expand argument n of Ts and Argument n of vs

Other discussion on variadic templates only seem to cover the simple variadic class templates and variadic functions such as typesafe printf etc. I am unsure as to how these different types of expansion effect the code and where each type would be useful.

Does anyone have some examples that demonstrate the application of each type of expansion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:56:28+00:00Added an answer on May 31, 2026 at 5:56 am
    #include <iostream>
    #include <memory>
    #include <typeinfo>
    #include <cstdlib>
    #include <cxxabi.h>
    
    template <typename T>
    std::unique_ptr<char, void(*)(void*)>
    type_name()
    {
        return std::unique_ptr<char, void(*)(void*)>
               (
                    __cxxabiv1::__cxa_demangle(typeid(T).name(), nullptr,
                                               nullptr, nullptr),
                    std::free
               );
    }
    
    void display() {}
    
    template <class T>
    void
    display()
    {
        std::cout << type_name<T>().get() << ' ';
    }
    
    template <class T, class T2, class ...Tail>
    void
    display()
    {
        std::cout << type_name<T>().get() << ' ';
        display<T2, Tail...>();
    }
    
    template <class... Ts>
    struct A
    {
        template <class... Us>
            static
            int
            hun(Us... us)
            {
                std::cout << "A<";
                display<Ts...>();
                std::cout << ">::hun(";
                display<Us...>();
                std::cout << ")\n";
                return 0;
            }
    };
    
    template <class ...T>
    void gun(T...) {}
    
    template <class... Ts> void fun( Ts... vs )
    {
        std::cout << "gun( A<Ts...>::hun(vs)...);\n";
        gun( A<Ts...>::hun(vs)...);
        std::cout << "\ngun( A<Ts...>::hun(vs...));\n";
        gun( A<Ts...>::hun(vs...));
        std::cout << "\ngun( A<Ts>::hun(vs)...);\n";
        gun( A<Ts>::hun(vs)...);
    }
    
    int main()
    {
        fun(1, 'a', 2.3);
    }
    

    Output:

    gun( A<Ts...>::hun(vs)...);
    A<int char double >::hun(int )
    A<int char double >::hun(char )
    A<int char double >::hun(double )
    
    gun( A<Ts...>::hun(vs...));
    A<int char double >::hun(int char double )
    
    gun( A<Ts>::hun(vs)...);
    A<int >::hun(int )
    A<char >::hun(char )
    A<double >::hun(double )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Andrei's talk on GoingNative 2012 he talks about Variadic Templates, and he explains
At the Boost library conference today, Andrei Alexandrescu , author of the book Modern
Has anybody used SmallObjectAllocator from Modern C++ Design by Andrei Alexandrescu in a big
I've read about Small-Object Allocation in Modern C++ Design. Andrei Alexandrescu argues that the
Andrei Alexandrescu writes in Modern C++ Design : The objects returned by typeid have
I am reading book called C++ coding standard By Herb Sutter, Andrei Alexandrescu and
I'm reading Andrei Alexandrescu's The D Programming Language and found this nugget in the
From Herb Sutter and Andrei Alexandrescu's 'C++ Coding Standards', Item 16: Avoid Macros under
I came across this article written by Andrei Alexandrescu and Petru Marginean many years
After reading Iterators must go by Andrei Alexandrescu, I tried to find a replacement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.