vendredi 24 juillet 2015

Can overloading shift operators for things other than I/O be a good design?

I am implementing the Open List (OL) class for the A* search algorithm. The OL is basically a specialized priority queue of search nodes. It is common to see a notation like this in the pseudo-code describing the A* algorithm:

    successorNode -> OL // put the successor node into OL
    ...
    curNode <- OL // get the best node from OL and store it in curNode

Three questions:

  1. Would it make sense for my OL class to support a similar notation by overloading the shift operators:

    OL ol;
    ...  
    OL << successorNode;
    ... 
    OL >> curNode;
    
    
  2. (Only if the answer to 1. is "Yes") Can I go as far as to support this (i.e. the usage not supported by cout and cin for the built-in types):

    OL ol;
    ...
    successorNode >> OL;
    ...
    curNode << OL;
    
    
  3. (Only if the answer to 1. is "Yes") Would this usage of the shift operators make sense for standard containers:

    vector<int> v;
    v << 5; // instead of v.push_back(5)
    
    

Aucun commentaire:

Enregistrer un commentaire