Working some Template Magic

Pages: 12
jsmith wrote:
It doesn't work if T implements operator& to do funny things.

Indeed. I totally forgot about that...

jsmith wrote:
(You need to use the boost::addressof() trick to ensure line 38 does what you want it to).

Or I could just do void * val_ptr() { return &reinterpret_cast<char&>(value);} :D
No, that doesn't work either, because T could be const or volatile, in which case you'll
get a compile error on your reinterpret_cast.

You need boost::addressof. :) Or else just duplicate it so you don't have to use boost :)

Also, I don't think the solution works if you have more than one source file.

EDIT:

Well, I suppose it would work if you pre-instantiated all of the statics for all of the types you'll
use in a separate cpp file:

template <class T>
int Type<T>::type;
Last edited on
Topic archived. No new replies allowed.
Pages: 12