C++ Metaprogramming
C++ suffers from a general problem that java doesn't - I can't create objects on the fly that fit into a particular framework - I have to know my interfaces at compile time. This hurts when trying to build dynamic interfaces like javascript engines at runtime.
Perhaps a new interface using templated collections?
class function {
protected:
setObject(object);
public:
virtual result_type run( list< stringpair > args ) ;
virtual operator=(string value);
}
class object {
public:
void add( string funcname, function func );
function operator() (string funcname);
}
You would invoke the function like so:
object(name).run( args );
Assigning a value might look like:
object(name) = value;
Enhancements:
- Maintain a Types collection for property storage. When a function is added to an object, the object informs it of ownership, and gives access to the internal types collection. This way when serialization needs to occur, it only happens on the Types collection - there is no need to do deep object inspection to serialize an object.
Detractions:
- This still doesn't fix the fact that objects need to be written at compile time. I can't use a tool like Java bytecode generation to create dynamic classes. It does however let me build object functionality at run-time based on known functors. Whether or not this is useful is debatable - you may not be able to decouple data in a generic enough way to make it worthwhile.