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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:25:25+00:00 2026-06-13T02:25:25+00:00

I am trying to copy a database table in a map where its the

  • 0

I am trying to copy a database table in a map where its the primary key will be the key of map and the rest of the columns are instances of boost:vector. I am new to boost as well as variadic templates. I have tried to write a wrapper, but it works fine only for a fixed number of columns. Following is the code

#include <boost/container/vector.hpp>
#include <iostream>
#include <string>
#include <map>
#include <type_traits>

typedef boost::container::vector<std::string> MAPPED_COLS;
typedef std::map <int,  MAPPED_COLS >    TABLE ;
typedef std::map <int,  MAPPED_COLS > ::iterator ROW_ITER;

typedef std::string  str;

template <typename str>
class MappedTable
{
    private:
            TABLE           mapTable;
            MAPPED_COLS     cols;
            ROW_ITER        row;

            std::string     scTableName;
            int             iRows;
            int             iCols;
    public:
            MappedTable()  { iCols=3; }

            MappedTable(int iNumCols)  { iCols=iNumCols;}
            ~MappedTable() { }

            template <str>
            void    fnRowCols()     //termination version
            {
            }

            template <str>
            void    fnCols(const str& scCol2, const str& scCol3,...)
            {
                    if(cols.size()>=iCols)
                    {
                          cols.erase (cols.begin(),cols.begin()+iCols);
                    }
                    cols.push_back(scCol2);

                    fnCols(scCol3,...);
            }

            template <str>
            void fnMapRow(int iCol1,const str& scCol2,...)
            {
                    fnCols(scCol2,...);
                    mapTable[iCol1]=MAPPED_COLS(cols);
            }


            MAPPED_COLS& fnGetRow(int iFindKey)
            {
                    row=mapTable.find(iFindKey);
                    if(row!=mapTable.end())
                            return (row->second);
            }
 };

Following is the main() for the above wrapper which works fine if i am not using variadic templates in my wrapper:-

 int main()
 {
    MappedTable Table(3) ;

    std::string vid[]={"11", "21", "51", "41"};
    std::string fare[]={"100", "400", "200", "4000"};
    std::string vehicle[]={"bus", "car", "train", "aeroplane"};

    int i=0;

    for(i=0;i<4;i++)
    {
            Table.fnMapRow(i,vid[i],fare[i],vehicle[i]);
    }

    for(i=0;i<4;i++)
    {
            MAPPED_COLS mpCol=Table.fnGetRow(i);
            std::cout<<"\n  "<<i<<" "<<mpCol[0]<<" "<<mpCol[1]<<" "<<mpCol[2];
    }

    std::cout<<"\n";

    return 0;
}

The code was compiled with Boost 1.51.0 and gcc 4.4 with std=c++0x option

Can anyone suggest me what is that i am missing?
I am open to better ideas and as well as keen to know how this particular example would work even if not efficient enough.

The working code snippet is available in my answer below (Thanks to Rost).
It would be great if anyone can suggest some better and more methods to store an entire table into a map.

Thanks !!

  • 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-13T02:25:26+00:00Added an answer on June 13, 2026 at 2:25 am

    Your variadic template function syntax doesn’t look correct. It shall be like this:

     template <typename... VarArgs>
     void fnCols(const str& scCol2, const str& scCol3, const VarArgs&... args)
     {
         // Non-relevant code skipped
         fnCols(scCol3, args...); // Recursive call with expanding arguments pack
     } 
    

    Similar problem with fnMapRow.
    Also template <str> is not needed before template member function definitions.

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

Sidebar

Related Questions

I am trying to copy from 1 table to another table on different database.
Trying to copy a database into a new database, using a PHP script that
Basically, I'm trying to selectively copy a table from one database to another. I
I am trying to copy a table from on MySQL database on a remote
I am trying to copy data from an old database into a new one,
I'm trying to do a simple copy of a table from one database to
I am trying to copy my pre-populated database to a writable directory (I am
I'm currently trying to copy data from table into another by using a SELECT
I'm trying to copy my production database on Heroku across to my staging server.
I am trying to copy a MyIsam dataBase from my a remote server to

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.