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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:14:19+00:00 2026-05-20T10:14:19+00:00

After a bit of investigation, I found that C++0x stores the elements in a

  • 0

After a bit of investigation, I found that C++0x stores the elements in a tuple backwards in memory.

For example, take this code:

std::tuple<char, char, char> x('\0', 'b', 'a');
char* y = (char*)&x;
std::cout << sizeof(x) << std::endl;
std::cout << y << std::endl;

When compiled with the GCC 4.5.2, I get the following output:

3
ab

This initially puzzled me. Why is the data stored backwards? After hunting through GNU’s unintentionally obfuscated headers, I noticed that the implementation was similar to this:

template<typename head, typename... tail> class tuple<head, tail...> : public tuple<tail...>
{
  head value;
  ...
};

Because the base class contains the last element, then the next derived class contains the second to last, etc., the actual order of the template arguments is reversed.

When I first got into tuples, I thought that I could use them for a function like glInterleavedArrays(), which sets an array of vertex data as tuples of colors, texture coordinates, normals, and points. Of course, if I make an array of tuples, this data will have to be inputted in reverse, which can result in really weird bugs if you happen to forget to put the arguments in the right order.

What about something like this, then?

template<typename... head, typename tail> class tuple<head..., tail> : public tuple<head...>
{
  tail value;
  ...
};

Under the GCC 4.5.2:

error: parameter pack argument ‘head …’ must be at the end of the template argument list

Unless this becomes available in the future, I’m pretty much stuck on finding another way to implement this. Is there another way? Some way to trick the GCC into getting a properly-ordered tuple memory-wise?

  • 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-20T10:14:19+00:00Added an answer on May 20, 2026 at 10:14 am

    The tuple layout that you are exploring is an unspecified implementation detail of tuple. Other implementations will have other layouts. If you write to this one, depending on gcc’s layout, your code may not be portable to other std::libs.

    The libc++ tuple implementation (for example) has the opposite (in-order) layout.

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

Sidebar

Related Questions

after a bit speedtracing I found a piece of code (called very very often)
After researching a bit how the different way people slugify titles, I've noticed that
UPDATE: After searching a bit I don't seem to be alone about this problem:
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
After a bit of research I've found what looks to be a good work
I've decided to look into Clojure (inspired by this book ). After a bit
After a bit of investigation I decided to use Carrierwave and mini_magick on my
I have this learning code I wrote for the morris seq in f# that
After a bit of digging it would appear that the WPF built in spell
After investigating a bit at work I noticed that the application I'm working on

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.