1

I am working in a C++11 solution, for Linux (Ubuntu 14.04; then I should need to migrate it to REL). I am using g++4.8 compiler (and I should probably be required to compile using Intel compiler).

But, please, focus on C++11 / Ubuntu 14.04 / g++4.8.

There are lots of Singleton implementations in the Web.

But it has been hard (and without success...) for me finding something like this:

  1. Ideal solution:
    A generic (template) Singleton, from where I can inherit my classes which contain STL containers.

  2. Acceptable solution:
    An "ad hoc" Singleton for each class with STL containers.

  3. "May be" possible solution:
    I am aware of the discussions about const and constexpr vs Singleton. But my managers are quite outdated. And they want a Singleton solution. But I think if I can provide a solution using const / constexpr would be acceptable.

Problem: The found solutions let me have a Singleton. But this Singleton not only avoid creating new instances of the class (which is my goal: only one instance), but also avoid inserting new elements in the STL containers (this is not desired at all).

So, I am looking for a Singleton + STL containers implementation:

  • which limits the created instances to only one.
  • which lets me add as many elements as I want in the queue, vector, set, map, list, array, and so forth, containers which belongs to the unique created object.
Cœur
  • 37,241
  • 25
  • 195
  • 267
Karol Baum
  • 63
  • 7
  • 1
    I did not quite understand the limitations of the singleton classes which you found online. You should post the code that you tried or may be provide a c++ "pseudo" code that shows how you want it to work. – Arunmu Nov 10 '16 at 06:27
  • Not sure what you want, but this maybe a duplicate http://stackoverflow.com/questions/17712001/how-is-meyers-implementation-of-a-singleton-actually-a-singleton?rq=1 – Danh Nov 10 '16 at 06:35
  • "*but also avoid inserting new elements in the STL containers*" That isn't necessary, it is probably because you decided to code it that way. – juanchopanza Nov 10 '16 at 06:43
  • It is really not clear to me, what you want to do and I also don't see the connection between singleton and `const`. Please give a (pseudo-) code example of what you want to achieve. – MikeMB Nov 10 '16 at 07:43

0 Answers0