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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:29:58+00:00 2026-06-16T19:29:58+00:00

I was reading Modern C++ design and not able to fully understand how template

  • 0

I was reading Modern C++ design and not able to fully understand how template template parameter works.

For example as given in this article http://www.informit.com/articles/article.aspx?p=376878 we can create a Stack with template parameters of type and containers .

If we use just type and container as parameter to template Stack then it may create some issues like

template <typename T, class Cont>
class Stack;

template <typename> class List;
Stack<int, List<int> > aStack1; // OK
Stack<double, List<int> > aStack2; // legal, not OK           
Stack<std::string, Deque<char *> > aStack3; // error! 

In above code I can understand that aStack1 is fine,aStack2 and aStack3 are issues because if incompatible types between Stack element type and container element type.

As per article this can be resolved if we use template template parameter

template <typename T, template <typename> class Cont>
class Stack;

Stack<int,List> aStack1;
Stack<std::string,Deque> aStack2;

My doubt here is how can Deque knows that its element type is std::string or List element type is int???Is this done by template argument deduction?

Here we are creating a Deque with type T .
If we have defined stack as

template <typename T,template U, template <typename> class Cont>
    class Stack;

then how can we instantiate Stack

   Stack<std::string,int,Deque> // will this work????
  • 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-16T19:29:59+00:00Added an answer on June 16, 2026 at 7:29 pm

    My doubt here is how can Deque knows that its element type is std::string or List element type is int???Is this done by template argument deduction?

    No, you explicitly instantiate the class template in the implementation of Stack which is likely to be implemented as:

    template <typename T, template <typename> class Cont>
    class Stack
    {
      Cont<T> _container; //here you use `T` as template argument to `Cont`
    
      Cont<int> _ints; //you can do even this if you need a containter of int.
                       //though in this case you don't need this.
    
      public:
            void push(T const & data)
            {
               _container.push_back(data); 
            }
            //etc
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading this page http://flask.pocoo.org/docs/patterns/streaming/ it seems like I might be able to do what
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied
Reading the Scala by Example book and there is this example when Martin explains
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
I've been reading Alexandrescu's book, Modern C++ design , and I've been quite impressed
(from reading chapter 3 of modern c++ design) typelist.hpp: class NullType {}; struct EmptyType
I've been reading an online article lately to learn the ropes of modern 3d
I am reading Modern C++ design. It was mentioned about sizeof opeator as following
I am reading modern C++ design. Following is the text snippet taken from typeinfo
After reading the Modern PHP workflow article in the November 2008 edition of php|architect

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.