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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:11:05+00:00 2026-05-28T04:11:05+00:00

I have a n-dimensional Boost.MultiArray I initialize as follows: const int n=3, size=4; //#

  • 0

I have a n-dimensional Boost.MultiArray I initialize as follows:

const int n=3, size=4; //# of dimensions and size of one dimension
boost::multi_array<char,n> arr;
boost::array<size_t,n> extents; //size of each dimension
extents.assign(size); //assign size to each dimension -> {{4, 4, 4}}
arr.resize(extents);

So I have 4 lines of code to get the MultiArray, but I’d like to do it in one line.
Is there any simple way to generate an MultiArray with n dimensions each having size length (so I can write arr(samevaluearray(n,size))) or did I miss a handy constructor for MultiArray?

Edit: It should work without depending on a certain value of n, i.e. arr({{size,size}} would only work for n=2.

Since it may not be clear: boost::multi_array<char,n>(boost::extents[4][4][4]) correctly initializes a 4x4x4-array, but every time n is changed in the sourcecode, every initialization has to be updated by hand, so it’s not an option.

  • 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-28T04:11:05+00:00Added an answer on May 28, 2026 at 4:11 am

    Turns out, std::vector has a constructor, that constructs a vector with a constant value repeated n times, so a possible solution looks like this:

    const int n=2, size=4; //# of dimensions and size of one dimension
    boost::multi_array<char,n> arr(std::vector<size_t>(n,size));
    

    This initializes a n-dimensional multi_array with each dimension’s size set to size.

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

Sidebar

Related Questions

I have a 2 dimensional array, like so: char[,] str = new char[2,50]; Now,
I have a one-dimensional array of strings in JavaScript that I'd like to turn
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multi-dimensional array, no problem. How do I interrogator one of the
I have a one dimensional array in VBScript that I would like to run
I have an single-dimensional array of PHP objects. Each object has two attributes, one
I have a one dimensional NumPy array: a = numpy.array([2,3,3]) I would like to
I have 2-dimensional array like below. unsigned char myArray[][48] = { {0xfc,0x94,0x88,0x48,0x5f,0xa4,0x9a,0xfb,0x6e,0xf8,0xcd,0x01,0x47,0x64,0x03,0xd0,0x1f,0xb8,0xa3,0x85,0x84,0xa9,0x4a,0xc4,0x9e,0xea,0x26,0x09,0x62,0x96,0x91,0xa6}, {0xa9,0xc5,0x9a,0xb3,0x09,0x38,0x15,0xb3,0x22,0xb3,0x07,0x21,0x3e,0x39,0x35,0xc6,0x69,0x6e,0xf3,0x64,0xb0,0x0a,0x4c,0xcb,0x77,0xff,0x76,0x3c,0x37,0xf3,0x99,0x96}, {0x24,0x4d,0xc0,0x45,0xe0,0x50,0x1f,0x72,0x0f,0xb0,0xcc,0xb9,0xc6,0x72,0xa9,0x5a,0xf3,0x5a,0xd9,0xe2,0xc3,0x44,0xd9,0x25,0xf3,0x12,0x6a,0x0c,0x37,0x6a,0x3f,0xb6},
I have a one dimensional gird. its spacing is a floating point. I have
I have a 2-dimensional array of objects, which I initialize using the traditional loop:

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.