define comparison operator at run time

  • Nobody/Anonymous

    I do not know in advance on which fields my dataset should be sorted, the sort fields are defined only by the user of the program. Is it possible to somehow define a comparison operator at run time ?

  • Johannes Singler

    Well, you can define a functor which decides at run-time what to compare, maybe something like this:

    bool operator()(const Structure& a, const Structure& b) const
       Key key;

         case lastname:
             return a.lastname < b.lastname;
         case firstname:
             return a.firstname < b.firstname;

    Remember that max_value() and min_value() have to work correspondingly, though maybe a switch is not necessary.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks