There´s a typeid operator that relies on RTTI and provides type information at runtime. Providing specialized templates allows compile time decision, and that´s probably what you want.
You can´t specialize member templates and you can´t partially specialize non member function, but you can use a (partially) specialized inserter template.
Code:// generic Edge Inserter template<typename Container, typename EdgeType> struct EdgeInserter { void operator()( Container& c, const EdgeType& e ) { // insert edge into container c.push_back( e ); } }; // specialized Edge Inserter template<typename Container> struct EdgeInserter<Container,Arc> { void operator()( Container&c, const Arc& a ) { // insert arc into container c.push_back( a ); } }; template<typename T, typename EdgeType> struct graph { EdgeInserter<EdgeContainerType,EdgeType> Inserter; // Container to hold edges (whatever this is) EdgeContainerType Edges; void add_edge( const EdgeType& NewEdge ) { // use inserter to add edge Inserter( Edges, NewEdge ); } };




Reply With Quote