Boost logo

Boost Users :

From: Victor A. Wagner Jr. (vawjr_at_[hidden])
Date: 2005-02-07 03:52:55


At Monday 2005-02-07 00:53, you wrote:
>Hi all,
>
>I'm having this particular class
>
>class File
>{
> public:
> int get_size();
> std::string get_name();
>
> private:
> int size,
> std::string name;
>} ;

kinda difficult to make name anything other than ""

>and a vector of objects of this class.
>vector <File> files ;
>
>and if want to sort the elements of the container i use
>stable_sort (files.begin(), files.end()) // Invokes operator < if its
>defined. otherwise shows up an error.
>there's another form of stable_sort, in which we can call a sorting
>function of our own.

sort(files.begin(), files.end(), binary_predicate)
exists

>Now my problem is the sorting criteria i use is dependent on runtime. say
>at times i want to sort by size and at other times i want to sort them by
>name of the file.
>
>The simple solution could be write 2 functions, sort_on_size and
>sort_on_filename which does the work.
>
>Now, the sorting order is also decided at runtime. So i write 2 more
>functions for that.
>
>The problem is the number of functions i use increase like any thing,
>which does not look good.
>
>The best way should be to use bind (or am i wrong here ?) from Boost library.
>
>But i'm not getting the syntax correctly here.
>
>the crude way could be
>
>stable_sort (files.begin(), files.end(), (bind (&File::get_size, _1) >
>bind (&File::get_size, _2))) ;
>
>that is call get_size() on first argument, and call get_size() on second
>argument, and compare those values, and return a boolean value.
>
>Can anybody please help me out with the syntax here. ??
>
>Thanks in advance,
>Surya
>
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users

Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
               "There oughta be a law"


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net