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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:37+00:00 2026-05-30T12:16:37+00:00

The implementation of std::vector that ships with Visual Studio 2010 and earlier versions has

  • 0

The implementation of std::vector that ships with Visual Studio 2010 and earlier versions has a well known particularity: the resize method has the following signature (C++03-compliant):

void resize(size_type new_size, value_type value);

instead of the C++11-compliant signature that’s been used by the majority of other STL implementations (like gcc’s STL or STLport) long before C++11:

void resize(size_type new_size, const value_type& value);

The problem with the first variant is that, in some situations, it will fail to compile if value_type has an alignment specification:

struct __declspec(align(64)) S { ... };
std::vector<S> v;  // error C2719: '_Val': formal parameter with __declspec(align('64')) won't be aligned

This is a well known problem with no satisfactory workaround apart from using a different implementation of std::vector.

I’m looking for a well-written, well-tested, self-contained and STL-compatible implementation of std::vector with a MIT-style licence that I could drop into my project as a container of choice for aligned types.

I considered extracting it from STLport or gcc’s STL but, being fully standard-compliant, they’re both large with many non-trivial dependencies.

(I would be perfectly happy with an implementation of a reasonable subset of std::vector that would only support push_back, clear, capacity, size, reserve, resize, swap and array indexing.)

Any ideas?

  • 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-30T12:16:38+00:00Added an answer on May 30, 2026 at 12:16 pm

    The guys behind the Eigen library seem to have found a nice workaround for the problem of storing “overly-aligned types” (as Stephan T. Lavavej call them) into a std::vector as implemented in Visual Studio’s STL.

    Their implementation seems unnecessary complicated (check the sources here and here) but the main idea is to encapsulate the type that goes into the std::vector with a thin wrapper:

    #include <vector>
    
    template <typename T>
    struct wrapper : public T
    {
        wrapper() {}
        wrapper(const T& rhs) : T(rhs) {}
    };
    
    struct __declspec(align(64)) S
    {
        float x, y, z, w;
    };
    
    int main()
    {
        std::vector< wrapper<S> > v;  // OK, no C2719 error
        return 0;
    }
    

    About the implementation in Eigen, I must admit I don’t quite understand

    • why they need Eigen::aligned_allocator_indirection,
    • why they need to make an exception for arithmetic types in EIGEN_WORKAROUND_MSVC_STL_SUPPORT,
    • why they need to define all these constructors and operators in Eigen::workaround_msvc_stl_support,
    • or why they need to redefine resize in their partial specialization of std::vector for the Eigen::aligned_allocator_indirection allocator…

    Clues welcome. The point is, this trick works perfectly (as far as I can tell) and I don’t see anything wrong with it, apart maybe from the slight inelegance.

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

Sidebar

Related Questions

I have a Visual Studio 2008 Windows Mobile 6 C++ application that is using
I recently installed Visual Studio 2010 Professional RC to try it out and test
Imagine that we have two static libraries built with different implementations of std::vector .
I have a class that adapts std::vector to model a container of domain-specific objects.
What strategy should I use if I have an implementation of std::fstream with 32-bit
I'm using a std::map (VC++ implementation) and it's a little slow for lookups via
Is std::string size() a O(1) operation? The implementation of STL I'm using is the
Let's say I have a: std::vector<std::list<Node> > And let's say Node is: class Node
A different question inspired the following thought: Does std::vector<T> have to move all the
I have an object that has a list of 'observers'. These observers get notified

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.