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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:21:55+00:00 2026-06-18T21:21:55+00:00

This seems to be a very simple question: How does one remove the first

  • 0

This seems to be a very simple question: How does one remove the first (the n-th) type in a std::tuple?

Example:

typedef std::tuple<int, short, double> tuple1;
typedef std::tuple<short, double> tuple2;

The operation described above would transform tuple1 into tuple2. Is it possible?

  • 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-18T21:21:57+00:00Added an answer on June 18, 2026 at 9:21 pm

    You can use a simple type function based on partial specialization of a class template:

    #include <type_traits>
    #include <tuple>
    
    using namespace std;
    
    template<typename T>
    struct remove_first_type
    {
    };
    
    template<typename T, typename... Ts>
    struct remove_first_type<tuple<T, Ts...>>
    {
        typedef tuple<Ts...> type;
    };
    
    int main()
    {
        typedef tuple<int, bool, double> my_tuple;
        typedef remove_first_type<my_tuple>::type my_tuple_wo_first_type;
    
        static_assert(
            is_same<my_tuple_wo_first_type, tuple<bool, double>>::value, 
            "Error!"
            );
    }
    

    Also, this solution can be easily generalized to remove the i-th type of a tuple:

    #include <type_traits>
    #include <tuple>
    
    using namespace std;
    
    template<size_t I, typename T>
    struct remove_ith_type
    {
    };
    
    template<typename T, typename... Ts>
    struct remove_ith_type<0, tuple<T, Ts...>>
    {
        typedef tuple<Ts...> type;
    };
    
    template<size_t I, typename T, typename... Ts>
    struct remove_ith_type<I, tuple<T, Ts...>>
    {
        typedef decltype(
            tuple_cat(
                declval<tuple<T>>(),
                declval<typename remove_ith_type<I - 1, tuple<Ts...>>::type>()
                )
            ) type;
    };
    
    int main()
    {
        typedef tuple<int, bool, double> my_tuple;
        typedef remove_ith_type<1, my_tuple>::type my_tuple_wo_2nd_type;
    
        static_assert(
            is_same<my_tuple_wo_2nd_type, tuple<int, double>>::value, 
            "Error!"
            );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Warning - I am very new to NHibernate. I know this question seems simple
Ok, very simple question this time (though the answer seems elusive for I can't
I have a simple question related to one-line programming. First an example: function test(a)
This is a very simple question, but I can't seem to find something about
This may seem a very silly question. Consider this: I have a simple Boolean
This problem seems very simple to me, but I've been unable to fix it,
This seems like it should be very simple but I can't get it to
This is a very simple question, but I haven't seem to be able to
This may seem like a very simple question, but I have been struggling with
My question is very simple. I will ask it first in case the answer

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.