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

  • Home
  • SEARCH
  • 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 8784993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:14:29+00:00 2026-06-13T21:14:29+00:00

I am trying to figure out which is the most idiomatic way implement a

  • 0

I am trying to figure out which is the most idiomatic way implement a function over a variadic type list. For example, computing the maximum size of all the types. I understand there exist several approaches to accomplish such a task, but I would like to know when to choose which strategy.

These are the mechanisms I would consider (there may exist more, please mention if so):

  • Type traits (ideally succinctly with using declarations):

    template <typename Head>
    using max_size = typename std::integral_constant<size_t, sizeof(Head)>::type;
    
    template <typename Head, typename... Tail>
    using max_size = ?;
    
  • constexpr functions:

    template <typename Head>
    constexpr size_t max_size() { return sizeof(Head); }
    
    template <typename Head, typename... Tail>
    constexpr size_t max_size() { ? }
    

My question is twofold:

  1. What features of the computation determine what strategy to choose?

  2. In each case, how would an example implementation for the maximum size example described above look like?

  • 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-06-13T21:14:30+00:00Added an answer on June 13, 2026 at 9:14 pm

    I personally prefer functions rather than traits, I find them easier to manipulate and more natural. But that’s certainly subjective 😉

    #include <iostream>
    
    template <typename Head>
    constexpr size_t max_size() { return sizeof(Head); }
    
    template <typename Head, typename Next, typename... Tail>
    constexpr size_t max_size() {
        return max_size<Head>() > max_size<Next, Tail...>() ?
               max_size<Head>() : max_size<Next, Tail...>();
    }
    
    int main() {
      std::cout << "int: " << max_size<int>() << "\n";
      std::cout << "char, short, int: " << max_size<char, short, int>() << "\n";
      std::cout << "char, double, int: " << max_size<char, double, int>() << "\n";
    }
    

    In action at liveworkspace:

    int: 4
    char, short, int: 4
    char, double, int: 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out exactly how to implement a callback function which
I'm trying to figure out the most efficient and scalable way to implement a
I am trying to figure out which is most appropriate. From the articles I
I'm trying to figure out a way to find out which files were affected
I'm trying to figure out which files get edited the most frequently. Is there
Well, basically I'm trying to figure out a way to get the 10 most
I am trying to figure out the best, or most efficient way of doing
I'm trying to figure out the most efficient way to generate a WHERE query.
I am trying to figure out how to iterate over an array which is
I'm customizing the UITableviewCells and I'm trying to figure out which is the most

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.