Re: Handling multiple selections in a Gtk::TreeView

Murray Cumming wrote:
When working with multiple selections, I find
myself using get_selected_rows() much more frequently, to get a vector
or list of selected rows, then iterating over that with a for loop. I
might use selected_foreach more if C++ had anonymous functions.

Yes, I think that get_selected_rows() was added sometime after
selected_foreach(), because it was more convenient.

I don't understand the comment about C++ not having anonymous functions.
Maybe that's C# terminology.

I'm not sure if C# supports anonymous functions, I was thinking more of Python, Haskell and Perl (Python and Haskell call them 'lambda functions'). They seem to be a feature of languages with late binding and functional languages (where functions aren't really distinct from values) rather than the more static kind of language, of which C++ is an example.

I don't know their exact syntax, but I believe that Gtk-Perl allows you to use anonymous subs as callbacks. If they have selected_foreach, that might look like this:

$treestore->selected_foreach(sub {
  # do something here

They're very handy, but don't really fit in the C++ mold. I suspect things like selected_foreach would be more useful if they did.

which one to use depends on what you want to do - sometimes
selected_foreach is more convenient.

Actually, I can't think of a case when it is right now. If you think of
one, let's document it.

To be honest, neither can I...

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]