On 10/27/2010 02:49 PM, Daniel Dilts wrote:
> I'm trying to figure out how to write a program that will, at run 
> time, say if a class is default constructable, but won't cause 
> compile-time failures if it isn't.
>
> I've been trying to use templates, but I'm just not familiar enough 
> with templates to get it to work.  What I would like is something like:
>
> // Class c is default constructable
> IsDefaultConstructable<c>::value == 1;
>
> // Class d is not default constructable
> IsDefaultConstructable<d>::value == 0;
>
> Does anybody have any ideas?


I believe the magic google search string will include "template 
metaprogramming". I'm not an expert in this area, and that's on purpose. 
I have found that programs employing this technique are error-prone, 
difficult to maintain, and hurt your brain (but not in a good way like 
how Scheme hurts your brain at first). The problem here is that C++ 
provides no run-time reflection feature.

Often programs that do crazy stuff like this will cause huge compile 
times, linkage failures, and other oddities when used on anything but 
the exact system configuration used by the original author.

While template metaprogramming itself is not necessarily evil, the C++ 
implementation is, in fact, pure evil.

So, my apologies for not being more helpful, but perhaps if you give us 
some context about what you're trying to accomplish, we can offer some 
ideas.

--Dave
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list

Reply via email to