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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:49:01+00:00 2026-06-10T13:49:01+00:00

In C++11, there are two versions of std::vector::resize() : void resize( size_type count );

  • 0

In C++11, there are two versions of std::vector::resize():

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

I understand (as suggested by one of the comments to one of the answers to this question) that the first requires value_type to be default constructible, while the second requires it to be copy constructible. However, (gcc 4.7.0)

using namespace std;
typedef int block[4];
vector<block> A;
static_assert(is_default_constructible<block>::value,";-("); //  does not fire
A.resize(100);                                               //  compiler error

So either my understanding was wrong or gcc is buggy. Which?

  • 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-10T13:49:03+00:00Added an answer on June 10, 2026 at 1:49 pm

    The requirement (23.3.6.3:10) on vector.resize(n) being well-formed is that T should be CopyInsertable, i.e. that the following should be well-formed (23.2.1:13):

    allocator_traits<A>::construct(m, p, v);
    

    where A is the allocator type of the vector, m is the allocator, p is of type T * and v is of type T.

    As you can discover from 20.6.8.2:5, this is invalid for array types in the general case as it is equivalent to calling

    ::new(static_cast<void *>(p))block(v);
    

    which is invalid for array types (arrays cannot be initialized by parentheses).


    Actually, you’re correct that g++ has a bug; it should always be possible to work around the issue with CopyInsertable by providing an appropriate allocator, but g++ fails to allow this:

    #include <vector>
    
    template<typename T, int n> struct ArrayAllocator: std::allocator<T[n]> {
        void construct(T (*p)[n], T (&v)[n]) {
            for (int i = 0; i < n; ++i)
                ::new(static_cast<void *>(p + i)) T{v[i]};
        }
    };
    
    int main() {
        std::vector<int[4], ArrayAllocator<int, 4>> c;
        c.resize(100);  // fails
    
        typedef ArrayAllocator<int, 4> A;
        A m;
        int (*p)[4] = 0, v[4];
        std::allocator_traits<A>::construct(m, p, v); // works
    }
    

    Another bug is in the standard itself; 20.9.4.3:3 specifies std::is_default_constructible<T> as equivalent to std::is_constructible<T>, where 20.9.4.3:6 specifies std::is_constructible<T, Args...> as the well-formedness criterion on T t(std::declval<Args>()...), which is valid for array types (as @Johannes Schaub-litb points out, array types can be initialised with (zero-pack-expansion)). However, 17.6.3.1:2 requires for DefaultConstructible in addition that T() be well-formed, which is not the case for an array type T but is not checked by std::is_default_constructible.

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

Sidebar

Related Questions

Consider the following program: #include <cstddef> #include <cstdio> void f(char const*&&) { std::puts(char const*&&);
In move.h, there're two overloads of forward template<typename _Tp> constexpr _Tp&& forward(typename std::remove_reference<_Tp>::type& __t)
In AssemblyInfo there are two assembly versions: AssemblyVersion : Specify the version of the
Is there any difference (compiler/interpreter/juju wise, etc) between the two versions of checking the
supposed there are two overloaded member function(a const version and a non-const version) in
There are two common ways to run mobile version of a website: Detecting the
I have read a document that they say: In java there two types of
There are two intents on the receiver side which are called from the same
There are two table s : one is the master and one the detail
There are two lists: List<string> excluded = new List<string>() { .pdf, .jpg }; List<string>

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.