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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:49:06+00:00 2026-06-06T16:49:06+00:00

I am trying to write a function that takes two containers of the same

  • 0

I am trying to write a function that takes two containers of the same contained type, e.g., two std::vector<int>s, or a std::list<int> and a std::vector<int>. (But not a std::vector<int> and a std::vector<double>!)

Since I am not quite sure regarding how it should be done, I decided to write a test progam first:

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

struct vector_wrapper
{
  template <typename T>
  struct instance_wrapper
  {
    typedef typename std::vector<T> instance;
  };
};

struct list_wrapper
{
  template <typename T>
  struct instance_wrapper
  {
    typedef typename std::list<T> instance;
  };
};

template <typename T, typename C1, typename C2>
void move(typename C1::instance_wrapper<T>::instance& c1, typename C2::instance_wrapper<T>::instance& c2) // line 29
{
  while (c1.size() > 0)
  {
    c2.push_front(c1.back());
    c1.pop_back();
  }
}

int main()
{
  std::vector<int> v;
  std::list  <int> l;

  v.reserve(10);
  for (int i = 0; i < 10; ++i)
    v.push_back(i);

  move<int, vector_wrapper, list_wrapper>(v, l);

  std::for_each(l.begin(), l.end(),
    [] (int i) { std::cout << i << " "; }
  );

  std::cout << std::endl;

  return 0;
}

This code gives me the following compile-time error with g++ 4.7, using the -std=c++11 flag:

metaclass.cpp:29:24: error: non-template 'instance_wrapper' used as template
... more ...

Why does the compiler not correctly identify instance_wrapper as a template?

  • 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-06T16:49:07+00:00Added an answer on June 6, 2026 at 4:49 pm

    Compiler has already told you what is wrong (errors from ideone):

    prog.cpp:25:24: error: non-template ‘instance_wrapper’ used as template
    prog.cpp:25:24: note: use ‘C1::template instance_wrapper’ to indicate that it is a template

    Use C1::template instance_wrapper instead of C1::instance_wrapper – and, similarly, do the same for C2::instance_wrapper:

    template <typename T, typename C1, typename C2>
    void move(typename C1::template instance_wrapper<T>::instance& c1, 
        typename C2::template instance_wrapper<T>::instance& c2)
    {
        // ...
    

    It’s because C1 is template and compiler cannot deduce that instance_wrapper is template and treats it as non-template type.

    Please, please, read everything compiler outputs. Not just line-by-line. Often compiler says what’s wrong in one of previous or following lines, as in this case, when it’s already giving you the answer!

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

Sidebar

Related Questions

I am trying to write a binary function that takes two vectors(of the same
I'm trying to write a merge-sort function that takes a list and a comparison
I'm trying to write a function that takes two string arguments and returns the
I am trying to write a function that takes two matrices as parameters and
I am trying to write a list function that takes a simple list and
I'm trying to write a simple function that takes two inputs, x and y
I'm trying to write a haskell function that takes in two lists of integers
I'm trying to write a function that takes a void pointer to an int
Trying to write a for function that takes two strings and returns the characters
I am trying to write a custom function that takes two cell ranges (Start

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.