Templates ‘o’ doom

Why, in C++, do templates have to be so damn gnarly?

I am pretty certain that, if I took the time to really learn templates, that I would be able to solve most of my own issues with them. But that initial learning seems to be a learning curve that would make Olympus Mons blush.

I’ve been trying to create a wrapper template that wraps type T with accessors so that it is modification aware (i.e. there’s a timestamp so I can tell when members were modified). The members need to be aware of the parent, though, which I’ve done with references. Unfortunately, the parent class doesn’t know about the children, so I can’t fathom a way to deal with the copy constructor, which means you can’t use it properly with stl containers.

Just getting that far I ran into all kinds of issues with partial template specialization, I guess a chunk of which will be solved by the C++0x extern template feature. I just couldn’t figure out how to declare member-function specializations inside the template class; declaring them extern caused “before instanation” errors, and declaring them after the class lead to duplication errors at link time.




I’d like to think I know about templates, but I couldn’t understand what you’re trying to do.

But wrt the stl and non-copyable containers, you can just use put it in a vector using shared_ptr. (Assuming the overhead is acceptable.)

Leave a Reply

Name and email address are required. Your email address will not be published.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

You may use these HTML tags and attributes:

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <pre> <q cite=""> <s> <strike> <strong> 

%d bloggers like this: