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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:18:02+00:00 2026-05-24T16:18:02+00:00

In C++0x (ohh! read C++11), we have automatic type inference. One thing which made

  • 0

In C++0x (ohh! read C++11), we have automatic type inference. One thing which made me curious was that I can’t create an array of auto variables. For example:

auto A[] = {1, 2, 3, 4}; // Error!

Any ideas why this might have been disallowed?

  • 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-24T16:18:03+00:00Added an answer on May 24, 2026 at 4:18 pm

    auto deduces every brace-enclosed initializer list to a std::initializer_list<T>. (See §7.1.6.4.6 including the example).
    Unfortunately you cannot initialize an array or even std::array from a std::initializer_list once you have obtained it, but you can use a std::vector.

    #include <vector>
    #include <array>
    #include <initializer_list>
    
    int main()
    {
      auto x = {1,2,3};
      std::array<int, 3> foo1 = x; // won't work for whatever reason
      std::vector<int> foo2 = x; // works as expected
      return 0;
    }
    

    Of course this defeats the whole purpose of what you are trying to do.

    I tried writing a work around called make_array but had to realize that this cannot ever work as the size of an initializer_list isn’t part of its template arguments and so you only instantiate one make_array template for each T. This sucks.

    template<typename T> 
    auto make_array(const std::initializer_list<T>& x) 
         -> std::array<T, x.size()> { } // maaah
    

    Well, apparently you can go for the variadic-template hack mentioned here How do I initialize a member array with an initializer_list?

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

Sidebar

Related Questions

I need to generate a local timestamp in a form of YYYYMMDDHHmmSSOHH'mm'. That OHH'mm'
I have no one else to count unless this fantastic community, I know this
I have a page on which I am ajax-ing in a table which has
I have this query that works just fine, however I want to change my
I have found that Scala always has a natural explanation to anything. Always something
Hello , all my fellow coders! I've got a problem ohh chok! .. :P
Yoyo experts! I have several progressbars on my Windowsform (NOT WPF), and I would
Okay, I'm NOT a Java noob, it just so happens that I've forgotten a
I want to create a property grid like this: Ext JS Property Grid demo
<asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <script type=text/javascript> GOTO = function () { alert(yes); $.ajax({ cache:

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.