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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:37:58+00:00 2026-05-10T23:37:58+00:00

Is there a good way in C++ to implement (or fake) a type for

  • 0

Is there a good way in C++ to implement (or fake) a type for a generic vector of vectors?

Ignore the issue of when a vector of vectors is a good idea (unless there’s something equivalent which is always better). Assume that it does accurately model the problem, and that a matrix does not accurately model the problem. Assume also that templated functions taking these things as parameters do need to manipulate the structure (e.g. calling push_back), so they can’t just take a generic type supporting [][].

What I want to do is:

template<typename T> typedef vector< vector<T> > vecvec;  vecvec<int> intSequences; vecvec<string> stringSequences; 

but of course that’s not possible, since typedef can’t be templated.

#define vecvec(T) vector< vector<T> > 

is close, and would save duplicating the type across every templated function which operates on vecvecs, but would not be popular with most C++ programmers.

  • 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. 2026-05-10T23:37:58+00:00Added an answer on May 10, 2026 at 11:37 pm

    You want to have template-typedefs. That is not yet supported in the current C++. A workaround is to do

    template<typename T> struct vecvec {      typedef std::vector< std::vector<T> > type; };  int main() {     vecvec<int>::type intSequences;     vecvec<std::string>::type stringSequences; } 

    In the next C++ (called c++0x, c++1x due to 2010), this would be possible:

    template<typename T> using vecvec = std::vector< std::vector<T> >; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a good way to implement many-to-many relation between rows in single table?
Is there a good way to implement this in Mozilla? I have done it
Is there a good way to implement an execution policy that determines which Thread
Hi is there a good way to implement drop downs so that they're functional
Is there any good way to deal with the class renaming refactor from Resharper
Is there a good way for displaying unicode text in opengl under Windows? For
Is there a good way to create a form in VB6 that can easily
Is there a good way to see what format an image is, without having
Is there a good way to find out which exceptions a procedure/function can raise
Is there a good way to time SQL queries when using Linq to SQL?

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.