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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:41:04+00:00 2026-06-11T04:41:04+00:00

As a matter of interest, lets say I have the following class: class Data

  • 0

As a matter of interest, lets say I have the following class:

class Data
{
public:
    template<class T>
    std::vector<T> getData(std::string& dataName);
private:
    ...
}:

So the class stores a set of vectors of any type. Each vector has a name and I know its type when retrieving it. What container might I use to store this data within the Data class? A std::vector<std::pair<std::string,std::vector<T>>>?

UPDATE:

I will also need to iterate over this class and the items must be in the same orders as I added them.

For example, I might have:

ownerNames: std::vector<std::string>;
ipAddress: std::vector<char>;

in my store. So when I iterate I need them in this order.

  • 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-11T04:41:06+00:00Added an answer on June 11, 2026 at 4:41 am

    If you know the type upon retrieval, use a boost::any:

    struct Data
    {
        std::map<std::string, boost::any> store;
    
        template <typename T>
        std::vector<T> & get(std::string const & s)
        {
            boost::any & a = store.find(s)->second;       // check existence!
            return boost::any_cast<std::vector<T> &>(a);  // try/catch bad cast!
        }
    
        template <typename T>
        bool put(std::string const & s, std::vector<T> v)
        {
            return store.emplace(s, std::move(v)).second;
        }
    };
    

    Usage:

    void f(Data & d)
    {
        try
        {
            auto & v = d.get<int>("MyNumbers");
        }
        catch (boost::bad_any_cast const & e)
        {
            std::cout << "'MyNumbers' is not an int-vector.\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to represent bank: class Bank { friend class InvestmentMethod; std::vector<BaseBankAccount*>
Following matter is JBossAS 7.1 Developer Guider: Change ResourceBundle location In previous versions of
After extensive searching on this matter, I have been unable to find an answer
Possible Duplicate: Does the order of class definition matter in PHP? class a {
No matter what i attempt i keep getting the following exception being thrown by
As a matter of academic interest, does using bind templates (esp in boost::lambda) prevent
I have the following SQL query Select cLedgerName,dDateFrom,cPeriodType,nPeriodFrom,nPeriodTo from sys_Account_Ledger a,sys_Log_Deposits_Interest_Master b where a.cGLCode=b.cGLCode
As a matter of general interest I'm wondering if there's a more elegant/efficient way
So we have this web app where we support UTF8 data. Hooray UTF8. And
No matter what I try, it never matches the sign. I even tried using

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.