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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:37:34+00:00 2026-06-09T00:37:34+00:00

Can I assume that for any type T , the type std::list<T> will have

  • 0

Can I assume that for any type T, the type std::list<T> will have a same, constant size? Just to make it clear, I mean the size of the ‘main’ type itself only, not of the memory allocated by it.

It seems logical to me to assume that the size of T itself should only affect the size of list nodes allocated using the allocator.

However, there are two things that might cause the variancy of sizeof(std::list<T>) I can think of:

  1. A standard C++ library trying to ‘optimize’ the std::list type by putting some of T instances into the std::list<T> itself. That seems like a bad idea to me, and it probably breaks the ‘constant time’ requirements put by the standard;
  2. A standard C++ having library specializations of std::list<T> for some types, with the specializations having different sizes.

I can’t think of any uses for (1) or (2) but I may be wrong.

What I’m thinking of achieving is using a fixed-size slice allocator for a template class usingstd::list<T> inside.


As a note: this is about variance for different types of T, and not for different allocators. I will have an explicit control of all instantiations, and they all will use the std::allocator.

  • 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-09T00:37:35+00:00Added an answer on June 9, 2026 at 12:37 am

    Yes, it can.

    The standard does not precise any guarantee on the size of a list<T> object as far as I am aware. Still, there are other guarantees.


    Let us debunk some things:

    A standard C++ library trying to ‘optimize’ the std::list type by putting some of T instances into the std::list<T> itself. That seems like a bad idea to me, and it probably breaks the ‘constant time’ requirements put by the standard;

    It does not break the ‘constant time’ requirement in any way as long as this number is bounded since O(5) is O(1). However, during a splice operations, the nodes should move from one list to another without moving in memory. Thus local storage is prohibited.

    A standard C++ having library specializations of std::list<T> for some types, with the specializations having different sizes.

    Since we already excluded the possibility of local storage, it is hard to imagine any other variations of the base std::list<T> type by itself.


    And let us worry about what matters:

    The memory allocated by a std::list<T> is provided by its second template argument: the allocator. Most allocators (including std::allocator<T> which is the default) use a simple pointer type: T*… however an allocator should feel free to change this type.

    Therefore, by changing the allocator parameter (and more precisely, its pointer type), one will naturally change the size of the std::list container in all the implementations I have seen of it.

    Note that the allocator itself could be specialized for some types, however with the rebind magic it’s a bit more difficult to achieve.

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

Sidebar

Related Questions

I have to parse a String that can assume hex values or other non-hex
Assume that we have a large file which can be read in chunks of
Assume that we have multiple arrays of integers. You can consider each array as
I want to create a helper method that can take in ANY type of
Can I some how make my non-exception objects become 'throwable' so that any local
First, I can assume that all urls that end with jpeg, jpg, bmp, png
From the disassembly code below can I assume that the location 43E010 is a
I assume that MAMP environment variables can be set in ~/.bash_profile, but it seems
Let's assume that our system can perform actions, and that an action requires some
Let's assume that I can't script the loaded swf, nor can the loaded one

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.