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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:45:15+00:00 2026-06-05T13:45:15+00:00

First the apologies, i’m not sure if my question title even accuratly explains what

  • 0

First the apologies, i’m not sure if my question title even accuratly explains what I’m asking – I’ve had a look through google, but i’m not sure which terms I need in my search query, so the answer may be out there (or even on StackOverflow) already.

I have a templated class, which basically looks like the following – it uses the Singleton pattern, hence everything is static, I’m not looking for comments on why I’m storing the keys in a set and using strings etc, unless it actually provides a solution. There’s a bit more to the class, but that isn’t relevant to the question.

template<typename T>
class MyClass 
{
private:
  //Constructor and other bits and peices you don't need to know about
  static std::set<std::string> StoredKeys;
public:
  static bool GetValue(T &Value, std::string &Key)
  {
    //implementation
  }

  static SetValue(const T Value, std::string &Key)
  {
    //implementation
    StoredKeys.Insert(Key);
  }

  static KeyList GetKeys()
  {
    return KeyList(StoredKeys);
  }
};

Later on in some other part of the application I want to get all the Keys for all of the values – regardless of type.

Whilst I am fairly confident that at the moment only 3 or 4 types are being used with the class so I could write something like:

KeyList Keys = MyClass<bool>::GetKeys();
Keys += MyClass<double>::GetKeys();
Keys += MyClass<char>::GetKeys();

This will need to be updated each time a new type is used. It also has the downside of instantiating the class if it’s not used anywhere.

I think (again I could be wrong) that metaprogramming is the answer here, some sort of macro maybe?

We’re using boost, so I’m guessing the MPL library could be useful here?

This aspect of STL is a bit new to me, so I’m happy to read up and learn as much as I need, just as soon as I know exactly what it is I need to learn to engineer a solution.

  • 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-05T13:45:18+00:00Added an answer on June 5, 2026 at 1:45 pm

    Move StoredKeys into a non-template base class class MyClassBase, or add an AllStoredKeys static member to a non-template base class.

    Alternatively, create a static init method called from SetValue that adds a pointer to StoredKeys to a static list.

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

Sidebar

Related Questions

First off, I'm not entirely sure that my question title is very descriptive, so
First: apologies for the question title, I don't actually know what the problem is
First of all apologies for the poor unclear question title, it is quite a
First, I do not do JS so apologies in advance for the noob question.
apologies if I make any cardinal errors in question asking, this is my first
First, I'm not sure if I should break this question into smaller, individual questions.
First - apologies for the fuzzy title, I could not find a better one.
First of all apologies, if the question title misleads you. Here is what I
this is my first time asking a question here so apologies if I am
First of all, my apologies for the title of this question, I don't have

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.