Well now. I defined

bool FormatsCompare( Format const & a, Format const & b )
{
        return( a.name < b.name );
}
and then
        sort( formats_vec.begin(), formats_vec.end(), &FormatsCompare );

And something similar for sorting Commands:

bool CommandCompare( Command const & a, Command const & b )
{
        if( a.from->prettyname == b.from->prettyname )
                return( a.to->prettyname < b.to->prettyname );
        else
                return( a.from->prettyname < b.from->prettyname );
}
        sort( commands_vec.begin(), commands_vec.end(), &CommandCompare );

Which all seems to work fine. Is your way "better"?
Anyway, thanks for the hint.
Angus

ps. I now have a fully working formats tab. It even posts a warning when I 
try and delete a Format used in an existing converter Command. (Not yet 
submitted.) Presumably, to do the same with the Converters tab I should do as 
you have done with the Formats class. Ie make it non-static and define two 
instances, a system_converters and a user_converters or similar.

A.


On Tue, 07 Nov 2000, Dekel Tsur wrote:
> On Tue, Nov 07, 2000 at 09:39:22AM +0000, Angus Leeming wrote:
> > > why aren't you doing it the way I originally did ? namely
> > >
> > > int i = fl_get_browser(formats_->browser_formats);
> > > if (i > 0) {
> > >           Format const & f = formats_vec[i-1];
> > >           fl_set_input(formats_->input_format, f.name.c_str());
> >
> > Because I sort the list of names (which I store). If I could sort the
> > list of formats by name, then I'd do that instead. Note that the STL is
> > largely unknown to me and whilst I do have reference literature, I find
> > that I tend to use example (eg find_if(), compare_memfunc()) to expand my
> > coding base.
>
> Use
> struct compare_formats {
>      bool operator()(Format const & a, Format const & b) {
>         return a.name < b.name;
>      }
> }
>
> and then
>     sort(formats_vec.begin(), formats_vec.end(), compare_formats());
>
> PS Is there a template for simplfying this ?

Reply via email to