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 6124015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:05:02+00:00 2026-05-23T16:05:02+00:00

For silly reasons I’ll not go into here, I need the commented out line

  • 0

For silly reasons I’ll not go into here, I need the commented out line to work and the line above it it to not work:

template<uint _N, typename... _Args>
struct PartialTuple;

template<uint _N, typename _Arg, typename... _Args>
struct PartialTuple<_N, _Arg, _Args...>: PartialTuple<_N-1, _Args...> {};

template<typename _Arg, typename... _Args>
struct PartialTuple<0, _Arg, _Args...>
{
    typedef std::tuple<_Arg, _Args...> type;
};

int main()
{
    // I want this to not work...
    PartialTuple<1, std::string, std::string, int, int>::type A{"test", 5, 1};

    // I want this to work...
    //PartialTuple<1, std::string, std::string, int, int>::type B{"test", "test", 5};
}

I tried swapping _Arg with _Args..., but that won’t compile (at least in GCC 4.6):

error: parameter pack argument ‘_Args ...’ must be at the end of the template argument list

How can I pull items off from the tail instead of from the head?

  • 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-23T16:05:03+00:00Added an answer on May 23, 2026 at 4:05 pm

    Here’s a solution: Instead of truncating N from the back, I just truncate sizeof...(Args) - N from the front:

    #include <tuple>
    
    /* Concatenator helper */
    
    template <typename T, typename Tuple> struct cat;
    template <typename T, typename ...Args>
    struct cat<T, std::tuple<Args...>>
    {
      typedef typename std::tuple<T, Args...> value;
    };
    
    
    /* Head-of-tuple */
    
    template <unsigned int, typename...> struct tuple_head;
    
    // Base case. Need to specialize twice, once for one and once for variadic types
    template <typename ...Args>
    struct tuple_head<0, Args...>
    {
      typedef std::tuple<> value;
    };
    template <typename T>
    struct tuple_head<0, T>
    {
      typedef std::tuple<> value;
    };
    
    // Recursion step
    template <unsigned int N, typename T, typename ...Args>
    struct tuple_head<N, T, Args...>
    {
      typedef typename cat<T, typename tuple_head<N - 1, Args...>::value>::value value;
    };
    
    
    /* User interface */
    
    template <unsigned int N, typename ...Args>
    struct PartialTuple
    {
      typedef typename tuple_head<sizeof...(Args) - N, Args...>::value type;
    };
    
    
    /* Usage */
    
    #include <string>
    int main()
    {
      // I want this to not work...
      //PartialTuple<1, std::string, std::string, int, int>::type A{"test", 5, 1};
    
      // I want this to work...
      PartialTuple<1, std::string, std::string, int, int>::type B("test", "test", 5);
      PartialTuple<0, std::string, std::string, int, int>::type C("test", "test", 5, 6);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Silly question, right? alas, i need a definite answer, Here's the sitch: We Built
For various silly reasons, I'd like to be able to detect the rectangle of
Here's a pretty silly question, but we want to do this. Is there an
For some unknown reasons this silly thing cant be implemented. I have an int
This may be a silly question about inheritance, but it does not make much
I must be missing something, silly, but here is the problem. I have a
Kick me if I'm being silly but some some reason I'm having a heck
This is almost certainly a very silly question, but for some reason I'm having
Silly question - Is there a way to download the iPhone SDK without Xcode
A silly question, perhaps, but at this time of night, StackOverFlow is my only

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.