Re: [Qt5-feedback] Lambdas
- Original Message From: Thiago Macieira thi...@kde.org Em Thursday, 30 de June de 2011, às 08:19:09, Konrad Rosenbaum escreveu: It feels much more natural to write something like mylsist.contains(...) than qContains(mylist,...) - Qt is supposed to be object oriented after all. It would be if (qFind(mylist, [](Type t) { return t.isFoo(); }) != mylist.end()) But anyway, that's a question to OO developers: where do you draw the line? The purpose of a class is to protect and mutate the invariant, the internals that the class is holding. It's not supposed to do everything under the sun. For example, QDate will not have a method QDate QDate::firstFridayThisMonth() const. I personally think that the kind of container operations you're asking for are just too specific to be part of the class. I'd prefer to have them outside. Yesterday, Konstantin was asking me for a qFiltered(InputIterator, InputIterator, const T value) that would return a list containing just the values that matched. So are we going to add all of the QtConcurrent operations too? filtered, filterReduced, mapped, mapReduced? While I quite agree that a line has to be drawn somewhere, I also find it a little annoying that for some containers there is a built-in find(), while for others there are not. So from that perspective, I would argue that there should be some consistency between find()/contains()/etc that use default quick-methods - even if they just default to using the qFind()/etc functions and make a nice wrapper around them. So, from my perspective - the containers _should_ have a basic functionality as being requested. It need not meet every circumstance - let the other qFind*/etc functions take care of that. For instance, if I want to ensure that I search mylist using a binary search, then qBinaryFind() is what I want. If I could care less, then I should be able to just do mylist.find(). Having a contains() function is also very useful for QVector, QList, etc as it makes for a very quick way to determine if something is there using syntax that is natural and straight forward. Lambdas may enable one do so - but then the syntax is not nearly as reader friendly - even without the lambdas it's not reader friendly. Just $0.02 on the topic. HTH, Ben ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
On Monday 27 June 2011, Thiago Macieira wrote: Em Monday, 27 de June de 2011, às 10:33:08, Ivan Cukic escreveu: I'm mostly interested in adding methods for Qt's collections (mapping, filtering, folding... and stuff commonly found in functional pls) To be honest, I'd rather we avoid adding more methods to the functional and algorithmic parts. We should provide the basic algorithms (qCopy, qStableSort, qLowerBind, etc.), but anything else should be just STL. How about extending the basic methods of collections - just the other day I wished I had abilities that are normal for SmallTalk programmers. One example: you want to know whether a list contains an element that matches a specific pattern. I recently had to refactor some code that does this. Old version (the list contains just names): QStringList mylist; //... if(mylist.contains(hello))doSomething(); New Version (the elements stored have more than names now): struct mydata { QString name,data; }; QListmydata mylist; //... for(int i=0;imylist.size();i++) if(mylist[i].name==hello){ doSomething(); break; } ...this is rather verbose and inelegant. What I would have liked would have been a lambda based approach: struct mydata { QString name,data; }; QListmydata mylist; //... if(mylist.contains( [](mydatadat){return dat.name==hello;} ) ) doSomething(); As a comparison SmallTalk has the following standard methods for all collections: mycollection do: [:x|some code: x] - executes the code for every element in the collection newcollection := mycollection select: [:x | criteria compare: x] - executes the criteria on every element and expects a boolean result, if it is true the element will be included in the result collection - there is also a reject: method that excludes anything that matches mycollection detect: [:x | criteria compare: x] - returns the index of the first element that matches the criteria - indexOf: works like the one in Qt, detect: uses a lambda instead - includes: is comparable to current Qt contains() mycollection occurencesOf: [:x | criteria compare: x] - counts how many match newcollection := mycollection collect: [:x | x * 2] - creates a new collection that contains every element transformed by the given expression mycollection conform: [:x | criteria compare: x] - returns true if ALL elements conform to the criteria These methods have proven to be extremely useful in the SmallTalk projects that I have done. Now that lambdas do exist for C++ I believe they will be just as useful here. Konrad PS: for those unfamiliar with SmallTalk: object method: parameter would be object.method(parameter); in C++ [ some code ] is a code block, it is comparable to a lambda expression, the last statement is the return value of the block, C++ would be: [](){return some.code();} - SmallTalk always uses references, so I translated with to C++ [ :parameter | some code: parameter ] is a code block with parameter, in C++: [](Type parameter){return some.code(parameter);} signature.asc Description: This is a digitally signed message part. ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
Em Wednesday, 29 de June de 2011, às 21:27:57, Konrad Rosenbaum escreveu: if(mylist.contains( [](mydatadat){return dat.name==hello;} ) ) doSomething() Like I said, this is a job for external functions, like qFind or STL algorithms. -- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org PGP/GPG: 0x6EF45358; fingerprint: E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358 signature.asc Description: This is a digitally signed message part. ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
On 29 June 2011 20:54, Thiago Macieira thi...@kde.org wrote: Em Wednesday, 29 de June de 2011, às 21:27:57, Konrad Rosenbaum escreveu: if(mylist.contains( [](mydatadat){return dat.name==hello;} ) ) doSomething() Like I said, this is a job for external functions, like qFind or STL algorithms. Why? I'm not sure I agree. Qt exists to make developers' lives easier, and even at the Qt3 - Qt4 transition, when STL was fairly mature on many platforms, Qt kept their own container classes (for which I am very thankful, as they tend to provide a bit more convenience, although a lot of that is things like implicit sharing to make writing methods returning complex containers easier and foreach - for instance). And isn't this exactly what things like this are about? Convenience? If STL provides the same functionality in its basic containers, that's great, but we shouldn't limit ourselves to someone else's subset of functionality, should we? ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
Em Wednesday, 29 de June de 2011, às 22:26:13, Robin Burchell escreveu: On 29 June 2011 20:54, Thiago Macieira thi...@kde.org wrote: Em Wednesday, 29 de June de 2011, às 21:27:57, Konrad Rosenbaum escreveu: if(mylist.contains( [](mydatadat){return dat.name==hello;} ) ) doSomething() Like I said, this is a job for external functions, like qFind or STL algorithms. Why? I'm not sure I agree. Qt exists to make developers' lives easier, and even at the Qt3 - Qt4 transition, when STL was fairly mature on many platforms, Qt kept their own container classes (for which I am very thankful, as they tend to provide a bit more convenience, although a lot of that is things like implicit sharing to make writing methods returning complex containers easier and foreach - for instance). And isn't this exactly what things like this are about? Convenience? If STL provides the same functionality in its basic containers, that's great, but we shouldn't limit ourselves to someone else's subset of functionality, should we? I'm not saying anything about the STL containers, I'm saying we should use the STL algorithm functions that perform those tasks. We should even implement our functions as wrappers to the STL ones if possible, as the compiler writers probably did the best job possible. Unlike the containers, where we disagree on some basic functionality semantics, there aren't many ways to implement a linear search or a binary search. So why not use the STL functions there? -- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org PGP/GPG: 0x6EF45358; fingerprint: E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358 signature.asc Description: This is a digitally signed message part. ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
2011/6/30 Robin Burchell virot...@viroteck.net On 29 June 2011 20:54, Thiago Macieira thi...@kde.org wrote: Em Wednesday, 29 de June de 2011, às 21:27:57, Konrad Rosenbaum escreveu: if(mylist.contains( [](mydatadat){return dat.name==hello;} ) ) doSomething() Like I said, this is a job for external functions, like qFind or STL algorithms. Why? I'm not sure I agree. Qt exists to make developers' lives easier, and even at the Qt3 - Qt4 transition, when STL was fairly mature on many platforms, Qt kept their own container classes (for which I am very thankful, as they tend to provide a bit more convenience, although a lot of that is things like implicit sharing to make writing methods returning complex containers easier and foreach - for instance). And isn't this exactly what things like this are about? Convenience? If STL provides the same functionality in its basic containers, that's great, but we shouldn't limit ourselves to someone else's subset of functionality, should we? completely agree that this job is for functions like qFind/qBinaryFind, etc. I, personally, see no point in adding a convenience method per container class if there is an iterator-based function exists (think about qDeleteAll() as for example) moreover, using qBinaryFind() in the use-case described above could be some faster... Konstantin ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
On Monday 27 June 2011 10:33:08 ext Ivan Cukic wrote: Hi all, There was a discussion about one of the C++'s new features - namely lambdas with a conclusion that it'd be nice, but nothing specific was decided. I'm suggesting to create a 'working group' for this so that we can see what do people want and how to do it / where to stop and say 'this is enough' I'm mostly interested in adding methods for Qt's collections (mapping, filtering, folding... and stuff commonly found in functional pls) I guess we'd need some place to put the proposals, discuss them, and so on without making noise on this list. Any thoughts? I think it boils down to the question Does Qt 5 have to support compilers that don't do C++0x ? If yes, then we are basically back to the VC6 times when the interface was sprinkled with #ifdef's due to the missing member template support there. Andre' ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
Em Monday, 27 de June de 2011, às 13:18:20, Konstantin Tokarev escreveu: 27.06.2011, 13:11, Ivan Cukic ivan.cu...@kde.org: Andre wrote: Does Qt 5 have to support compilers that don't do C++0x ? Lambdas are (afaik) supported by the latest gcc, msvc and intel's c++ compiler. It is not possible to use latest compilers on every platform. For example, we are still stuck to gcc 2.95 for one of embedded platforms. GCC 2.95 is not supported. Minimum requirement for Qt 4.x today is GCC 3.4 and only because some RHEL versions still use that. For 5.0, I'd like to raise the minimum to GCC 4.2. -- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org PGP/GPG: 0x6EF45358; fingerprint: E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358 signature.asc Description: This is a digitally signed message part. ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
27.06.2011, 13:38, Thiago Macieira thi...@kde.org: Em Monday, 27 de June de 2011, às 13:18:20, Konstantin Tokarev escreveu: 27.06.2011, 13:11, Ivan Cukic ivan.cu...@kde.org;: Andre wrote: Does Qt 5 have to support compilers that don't do C++0x ? Lambdas are (afaik) supported by the latest gcc, msvc and intel's c++ compiler. It is not possible to use latest compilers on every platform. For example, we are still stuck to gcc 2.95 for one of embedded platforms. GCC 2.95 is not supported. Minimum requirement for Qt 4.x today is GCC 3.4 and only because some RHEL versions still use that. For 5.0, I'd like to raise the minimum to GCC 4.2. GCC 4.2 does not support c++0x anyway. -- Regards, Konstantin ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
On Monday 27 June 2011 11:32:05 ext Ivan Cukic wrote: It is not possible to use latest compilers on every platform. For example, we are still stuck to gcc 2.95 for one of embedded platforms. I am aware of those situations, but I'd rather /fix/ those than to keep the code ugly just so that it can compile with an old version of gcc. (having the stuff that doesn't compile could be an incentive for updating the compiler...) LLVM doesn't support them yet, but it is not yet stable enough to compile Qt properly (acc to the project's website) Nope, clang is able to compile Qt. I've read it here http://clang.llvm.org/cxx_status.html Qt Partially compiles; miscompilation of uic prevents complete compilation, qmake works, some small examples also. But if it does work, cool :) This was in February 9, 2010, more than 1 year ago. Since then, both Qt and clang have changed. http://labs.qt.nokia.com/2010/10/29/compiling-qt-with-clang/ ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
2011/6/27 Konstantin Tokarev annu...@yandex.ru LLVM doesn't support them yet, but it is not yet stable enough to compile Qt properly (acc to the project's website) Nope, clang is able to compile Qt. I am compiling QtCreator with Qt4 compiled using clang for several months. This is possible and working. Not tested Qt5. ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
Re: [Qt5-feedback] Lambdas
FWIW, We can code support for lambdas without using any C++11-specific features: template class Sequence, class Functor Sequence filter(const Sequence , Functor f); , will take a function pointer, a functor (object) or a lambda function all the same. With things like Boost.Lambda or Boost.Phoenix, you even have some variation of lambdas in C++03-supporting compilers. With things like that we can improve support for lambdas where it makes sense in the API (e.g. QThread, QRunnable and QtConcurrent). I don't, however see us adding a lot of functional stuff to the container classes as has been discussed elsewhere on this list. Cheers, João From: qt5-feedback-bounces+joao.abecasis=nokia@qt.nokia.com [qt5-feedback-bounces+joao.abecasis=nokia@qt.nokia.com] On Behalf Of Poenitz Andre (Nokia-MP-Qt/Berlin) Sent: 27 June 2011 10:52 To: qt5-feedback@qt.nokia.com Subject: Re: [Qt5-feedback] Lambdas On Monday 27 June 2011 10:33:08 ext Ivan Cukic wrote: Hi all, There was a discussion about one of the C++'s new features - namely lambdas with a conclusion that it'd be nice, but nothing specific was decided. I'm suggesting to create a 'working group' for this so that we can see what do people want and how to do it / where to stop and say 'this is enough' I'm mostly interested in adding methods for Qt's collections (mapping, filtering, folding... and stuff commonly found in functional pls) I guess we'd need some place to put the proposals, discuss them, and so on without making noise on this list. Any thoughts? I think it boils down to the question Does Qt 5 have to support compilers that don't do C++0x ? If yes, then we are basically back to the VC6 times when the interface was sprinkled with #ifdef's due to the missing member template support there. Andre' ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback ___ Qt5-feedback mailing list Qt5-feedback@qt.nokia.com http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback