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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:08:16+00:00 2026-05-17T18:08:16+00:00

When speaking about attribute lists I mean a generic list which stores additional information

  • 0

When speaking about attribute lists I mean a generic list which stores additional information for a class.

The simplest case:
A class has a std::map<std::string, std::string>. The first string names the attribute (like "Color"), the second string describes the value (like "Yellow").
In this example another class which uses these attributes needs to check if a certain attribute-name is existing in the map and then parse the value.
However this isn’t the best concept when talking about performance.

How would you implement such an attribute list?
Are there any design patterns or libraries which just do something like that?

I’m especially interested in a C++-way of doing this, but if there are language-independant solutions, please post them too.

An attribute list could be used in cases where a class needs to have dynamic attributes and the user does not want to inherit for each attribute.
If that helps, you could check my other question relating to that topic:
Attributelists or inheritance jungle?

EDIT:
Of course I forgot some information (thanks to the comments):
The attributes could be applied to objects. There could be different attributes for objects of the same class. The attributes an object has can change (the value can change, there could be attributes added/removed)
Hope this clearifies it a bit.

  • 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-17T18:08:16+00:00Added an answer on May 17, 2026 at 6:08 pm

    I did something similar.

    If the attributes are common for all instances of your class, make a separate Meta description of your class in which you describe the attributes. Then, per instance provide a simple vector of type boost::any (I don’t use boost::any but something similar that we wrote ourselves).

    If the attributes can be different per instance, make a map per instance where the key is an atom and the value is boost::any (or something similar). Under Windows atoms are a kind of numerical representation of a string. First use strings to indicate the ‘attribute name’, then convert this to an atom and use this as key in the map. Using the numerical atoms instead of strings will speed up the look up of attributes in the map (provided you keep the atom value somewhere and you don’t need to perform the string-to-atom lookup everytime you want an attribute value).

    Don’t use attributes as your normal way of storing class data members. If you do this, debugging will become a nightmare, since it will be very very very difficult to see what the actual values in your class are. Also putting watch points will become impossible.

    Only use these attributes to store things that you can’t put in a normal data member, e.g.:
    – you don’t know the attributes beforehand (e.g. they could be customer-specific)
    – you don’t want to introduce a dependency (even by name) between two classes

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

Sidebar

Related Questions

When speaking about casting here, I mean implicit cast. Assume class B inherits from
Speaking about compiled languages (c# in my case) I think that problem would always
I saw different articles speaking about OCR form recognition (data extraction) and they said
First, I'm speaking about the default hashCode() method here and not something overridden. When
can I programatically (or, as we're speaking about html and css , semantically) decide
@property (nonatomic, readonly) BOOL isBlabla; When speaking about properties I'm not sure what the
Possible Duplicate: Why C# implements methods as non-virtual by default? I'm speaking primarily about
Conceptually speaking how would one go about writing an achievement system for a website
Generally speaking, when given a cookie that has no expiration period, modern browsers will
I read the Book NHibernate in Action and there it is speaking about testing

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.