Should I use a templated class here?

Last edited on
1) yes, it sounds right, most containers are templates.

2) not as easily. you can do specializations, or you can have a requirement that what is given to your container have a .serializemyself() function that you call, or you can do other things like virtual that part out and make the user provide it. There are probably several other ways as well.

another way is to make entity_details have some optional fields, if you need a tiny bit of flexibility but not all-encompassing. Alternately, what all does it need that isn't provided by the map? The map is already templated, and you already need routine *somewhere* that serializes the thing, so how far off your goal are you if you just have map do all the work and you write a stand-alone serializer for each map you need?

what you have looks simple, but it may just be an example. Try to scope the problem -- if its going to become massively complicated later, you need to build a rich tool. If you just have a dozen or so simple c-structs to manage, see if you can square peg / round hole an stl container to do 99% of the work and keep it simple.
Whenever someone says make a new container, I tend to red flag it.. its been years since I made a container, the last was a tree, and it was really a wrapper for a vector.
Last edited on
int is different type than double and Entitycontainer<int> is different type than Entitycontainer<entity_details>

Will the user have many different containers, one for each dataset?
@rozick1 Please DON'T delete your question after it's been answered. It makes the thread useless for anyone else to learn from.
Topic archived. No new replies allowed.