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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:06+00:00 2026-05-27T17:15:06+00:00

I have a tuple of unknown size (it’s template parametr of method) Is it

  • 0

I have a tuple of unknown size (it’s template parametr of method)

Is it way to get part of it (I need throw away first element of it)

For example, I have tuple<int,int,int>(7,12,42). I want tuple<int,int>(12,42) here

  • 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-27T17:15:07+00:00Added an answer on May 27, 2026 at 5:15 pm

    With help of a compile-time integer list:

    #include <cstdlib>
    
    template <size_t... n>
    struct ct_integers_list {
        template <size_t m>
        struct push_back
        {
            typedef ct_integers_list<n..., m> type;
        };
    };
    
    template <size_t max>
    struct ct_iota_1
    {
        typedef typename ct_iota_1<max-1>::type::template push_back<max>::type type;
    };
    
    template <>
    struct ct_iota_1<0>
    {
        typedef ct_integers_list<> type;
    };
    

    We could construct the tail simply by parameter-pack expansion:

    #include <tuple>
    
    template <size_t... indices, typename Tuple>
    auto tuple_subset(const Tuple& tpl, ct_integers_list<indices...>)
        -> decltype(std::make_tuple(std::get<indices>(tpl)...))
    {
        return std::make_tuple(std::get<indices>(tpl)...);
        // this means:
        //   make_tuple(get<indices[0]>(tpl), get<indices[1]>(tpl), ...)
    }
    
    template <typename Head, typename... Tail>
    std::tuple<Tail...> tuple_tail(const std::tuple<Head, Tail...>& tpl)
    {
        return tuple_subset(tpl, typename ct_iota_1<sizeof...(Tail)>::type());
        // this means:
        //   tuple_subset<1, 2, 3, ..., sizeof...(Tail)-1>(tpl, ..)
    }
    

    Usage:

    #include <cstdio>
    
    int main()
    {
        auto a = std::make_tuple(1, "hello", 7.9);
        auto b = tuple_tail(a);
    
        const char* s = nullptr;
        double d = 0.0;
        std::tie(s, d) = b;
        printf("%s %g\n", s, d);
        // prints:   hello 7.9
    
        return 0;
    }
    

    (On ideone: http://ideone.com/Tzv7v; the code works in g++ 4.5 to 4.7 and clang++ 3.0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tuple with two numbers in it, I need to get both
I have a list of tuple, the list was sorted based on the first
I want to get a field from the last tuple I have inserted to
I have a property like this: public Tuple<String, String>[] Breadcrumbs { get; set; }
I have a tuple containing lists and more tuples. I need to convert it
I'm new to python. I have tuple. It's have a elements /dictionaries/. I need
I have a tuple of tuples and I want to put the first value
How could I unpack a tuple of unknown to, say, a list? I have
Let's say I have a tuple t = (1,2,3,4) . What's the simple way
I have the following tuple of tuples: my_choices=( ('1','first choice'), ('2','second choice'), ('3','third choice')

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.