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

  • Home
  • SEARCH
  • 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 6249279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:12:30+00:00 2026-05-24T13:12:30+00:00

In the C++0x Variadic Templates Proposal paper Link there is an example of a

  • 0

In the C++0x Variadic Templates Proposal paper Link there is an example of a class which supports an arbitrary number of dimensions. I have copied it below:

template<typename T, unsigned PrimaryDimension, unsigned... Dimensions>
class array { /* implementation */ };

array<double, 3, 3> rotation matrix; // 3x3 rotation matrix

Sadly the implementation is not provided. As I am relatively new to variadic templates I would be interested to see an implementation of this container.

Thanks to anybody who can provide a simple implementation.

  • 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-24T13:12:30+00:00Added an answer on May 24, 2026 at 1:12 pm

    Here is a very simple implementation (compiled with gcc4.6.1) that demonstrates the recursion involved in getting the array type right – if there is some other specific implementation detail you are interested in, please let us know:

    template<class T, unsigned ... RestD> struct array;
    
    template<class T, unsigned PrimaryD > 
      struct array<T, PrimaryD>
    {
      typedef T type[PrimaryD];
      type data;
      T& operator[](unsigned i) { return data[i]; }
    
    };
    
    template<class T, unsigned PrimaryD, unsigned ... RestD > 
       struct array<T, PrimaryD, RestD...>
    {
      typedef typename array<T, RestD...>::type OneDimensionDownArrayT;
      typedef OneDimensionDownArrayT type[PrimaryD];
      type data;
      OneDimensionDownArrayT& operator[](unsigned i) { return data[i]; }
    }; 
    
    int main()
    {
        array<int, 2, 3>::type a4 = { { 1, 2, 3}, { 1, 2, 3} };
        array<int, 2, 3> a5{ { { 1, 2, 3}, { 4, 5, 6} } };
        std::cout << a5[1][2] << std::endl;
    
        array<int, 3> a6{ {1, 2, 3} };
        std::cout << a6[1] << std::endl;
    
        array<int, 1, 2, 3> a7{ { { { 1, 2, 3}, { 4, 5, 6 } } }};
        std::cout << a7[0][1][2] << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a variadic function which takes an arbitrary number of arguments of
I have a class factory where I'm using variadic templates for the c'tor parameters
I have a variadic template function which calls itself to determine the largest number
I saw that @GMan implemented a version of sizeof... for variadic templates which (as
Is there a macro that tells me whether or not my compiler supports variadic
I'm porting FastDelegate to C++0x using variadic templates. #include FastDelegate.h template<class R=fastdelegate::detail::DefaultVoid, class ...P>
I have been playing around with variadic templates in the new c++ standard and
The thinking is that since variadic templates are a compile time feature, there will
I saw a blog post which used non-type variadic templates (currently not supported by
I'm trying to implement a delegate class following Herb Sutter's Example . There is

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.