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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:50:30+00:00 2026-05-25T01:50:30+00:00

I’m trying to create a static vector-of-vectors and I’m finding that the following code

  • 0

I’m trying to create a static vector-of-vectors and I’m finding that the following code compiles and runs under gcc-4.1.2 but under gcc-4.5.1 it fails to compile with the message

assign.cxx:19:48: error: no matching function for call to ‘to(boost::assign_detail::generic_list<std::basic_string<char> >&)’

Can anyone explain why this happens? If you have any other suggestions about how to do what I’m trying to do then I’d be happy with that instead :).

#include <iostream>
#include <string>
#include <vector>
#include <boost/assign/list_of.hpp>

template <template <typename> class containerType, typename elemType>
containerType<elemType> to( boost::assign_detail::generic_list<elemType> list ) {
  containerType<elemType> tempContainer = list;
  return tempContainer;
}

static const std::vector<std::vector<std::string> > names = boost::assign::list_of
  (to<std::vector>(boost::assign::list_of<std::string>("A")("B")("C") ))
  (to<std::vector>(boost::assign::list_of<std::string>("D")("E")("F") ));

int main() {

  for( std::vector< std::vector<std::string> >::const_iterator itVec = names.begin(); itVec != names.end(); ++itVec ) {
    for( std::vector<std::string>::const_iterator itStr = itVec->begin(); itStr != itVec->end(); ++itStr ) {
      std::cout << "Value is " << *itStr << std::endl;
    }
  }
  return 0;
}
  • 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-25T01:50:31+00:00Added an answer on May 25, 2026 at 1:50 am

    The problem stems from the fact that in your definition of to<>(), containerType is declared to have only one template parameter, when in fact std::vector<> has two template parameters.

    The fact that this compiles in GCC 4.1.2 only indicates a bug in GCC 4.1.2 — the code is still inherently incorrect.

    Unfortunately, I can’t think of a good workaround offhand. The following compiles but restricts you to containers with only two template arguments (wherein the second is the allocator), which may not be what you ultimately want:

    #include <iostream>
    #include <string>
    #include <vector>
    #include <boost/assign/list_of.hpp>
    
    template<
      template<typename, typename> class containerType,
      typename allocatorType,
      typename elemType
    >
    containerType<elemType, allocatorType >
    to(boost::assign_detail::generic_list<elemType> const& list)
    {
      return list; // no need to explicitly construct a containerType instance
    }
    
    template<template<typename, typename> class containerType, typename elemType>
    containerType<elemType, std::allocator<elemType> >
    to(boost::assign_detail::generic_list<elemType> const& list)
    {
      return to<containerType, std::allocator<elemType> >(list);
    }
    
    static std::vector<std::vector<std::string> > names = boost::assign::list_of
      (to<std::vector>(boost::assign::list_of<std::string>("A")("B")("C")))
      (to<std::vector>(boost::assign::list_of<std::string>("D")("E")("F")));
    
    int main()
    {
      typedef std::vector<std::vector<std::string> >::const_iterator outer_iter_t;
      typedef std::vector<std::string>::const_iterator inner_iter_t;
    
      for (outer_iter_t itVec = names.begin(); itVec != names.end(); ++itVec)
        for (inner_iter_t itStr = itVec->begin(); itStr != itVec->end(); ++itStr)
          std::cout << "Value is " << *itStr << '\n';
    }
    

    EDIT (in response to dribeas’ comment): Updated to allow the caller to override the default allocator.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

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.