Re: Do I need a singleton here? Or can I use std::move
On 19 Okt., 06:41, Jim Langston wrote:
I am developing a font class for my opengl graphics library and I came
across a quandry. I have a font which is simply a value for font id an=
wrapper code to load the font and kill it. Works fine, then I notice I
don't have a virtual destructor, nor any destructor at all. So I throw=
virtual destructor and call the code to unload the glfont. I run the
program, now no fonts are visible.
The problem is that my fonts are stored in a map by font name and the fon=
and of course std::maps along with most containers use copy.
I've been bitten by this before and wound up using pointers so I could
control when the destructor was called. This was okay since polymophis=
involved and I needed pointers anyway.
I thought about using some variant of a smart pointer but I would still b=
working with pointer logic.
Any suggestions? I am willing to use any feature of 0x that Express 2010
You could test whether this implementation already supports putting
std::unique_ptr<> objects into a map. This is supposed to work in the
upcoming C++ version but last time I checked it didn't work using GCC
4.5.1 in C++0x mode because the std::pair implementation wasn't able
to handle move-only types like std::unique_ptr<> yet.
I have heard somethign about std::move being in 0x and that std::vector a=
other containers were supposed to use std::move instead of copy.
Yes. The containers won't require the types to be copyable anymore.
Move-only types will be fine, too.