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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:59:09+00:00 2026-06-07T04:59:09+00:00

Code: std::vector<int> x{1,2,3,4}; std::array<int, 4> y{{1,2,3,4}}; Why do I need double curly braces for

  • 0

Code:

std::vector<int> x{1,2,3,4};
std::array<int, 4> y{{1,2,3,4}};

Why do I need double curly braces for std::array?

  • 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-07T04:59:11+00:00Added an answer on June 7, 2026 at 4:59 am

    std::array<T, N> is an aggregate: it doesn’t have any user-declared constructors, not even one taking a std::initializer_list. Initialization using braces is performed using aggregate initialization, a feature of C++ that was inherited from C.

    The “old style” of aggregate initialization uses the =:

    std::array<int, 4> y = { { 1, 2, 3, 4 } };
    

    With this old style of aggregate initialization, extra braces may be elided, so this is equivalent to:

    std::array<int, 4> y = { 1, 2, 3, 4 };
    

    However, these extra braces may only be elided “in a declaration of the form T x = { a };” (C++11 §8.5.1/11), that is, when the old style = is used . This rule allowing brace elision does not apply for direct list initialization. A footnote here reads: “Braces cannot be elided in other uses of list-initialization.”

    There is a defect report concerning this restriction: CWG defect #1270. If the proposed resolution is adopted, brace elision will be allowed for other forms of list initialization, and the following will be well-formed:

    std::array<int, 4> y{ 1, 2, 3, 4 };
    

    (Hat tip to Ville Voutilainen for finding the defect report.)

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

Sidebar

Related Questions

Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,
Is there any problem with my code ? std::vector<int[2]> weights; int weight[2] = {1,2};
Say, I have a std::vector<SomeClass *> v; in my code and I need to
Considering this code: std::vector<myObject*> veryLargeArray; for (int i = 0; i < veryLargeArray.size(); ++i)
I'll start with the code: typedef std::vector<unsigned char> CharBuf; static const int RCV_BUF_SIZE =
I'm trying to copy a QList in a std::vector this is my code: std::copy(_param_31.listJobs->list_USCOREjobs.begin(),
The code below is for storing a group of words in a std::vector and
Consider the following code: #include <iostream> #include <memory> #include <vector> using namespace std; struct
I have the following code: #include <iostream> #include <vector> using namespace std; struct A{};
When trying to compile this code: #include <iostream> #include <vector> using namespace std; class

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.