CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #3
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Equivalance Typeof Operator Suggestion

    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 );
       }
    };
    Last edited by GNiewerth; February 12th, 2009 at 05:43 AM.
    - Guido

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured