This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Use of C++11 features for kde development

Tags: None
(comma "," separated)
karthikp
Registered Member
Posts
109
Karma
0
OS
Is there an official stance on using (or not using) C++11 features in kde code. If so, does it depend on which version of the codebase I'm hacking on (example, 4.x versus kf5)?

As an example, I'm fixing a bug in sonnet (the spell checking framework) and I want to return true if any characters in a string are valid letters. What I would like to write is this:

Code: Select all
#include <algorithm>
#include <functional>
...
return std::any_of( str.begin(), str.end(), std::mem_fn( &QChar::isLetter ) );


But it doesn't compile. I tried avoiding mem_fn() and used a lambda, which doesn't compile either as lambdas are not available in C++98. Also, it complains that any_of is not a member of std, which is weird.

I made do with this:

Code: Select all
for ( int i = 0; i < str.length(); ++i ) {
    const QChar chr = str.at( i );
    if ( chr.isLetter() ) return true;
}
return false;


So, this got me wondering. Is there a rule/consensus/prevailing opinion about using C++11 in kde development? And if so, does it apply to the 4.x codebase only or both to 4.x and the new frameworks as well?


karthikp, proud to be a member of KDE forums since 2008.
Image
User avatar
ivan
KDE Developer
Posts
918
Karma
14
OS
I have been pushing the idea of requiring more modern compilers for some time now. The general agreement was to (for the libraries) support the same platforms the used version of Qt supports.

The conclusion for KF5 is covered here: http://lists.kde.org/?l=kde-core-devel& ... 624704&w=2

For kdelibs 4.x, the situation is not as nice - gcc 4.2 and equivalent.

For the non-library projects, the situation is not really clear - every project has its own rules.


Image
karthikp
Registered Member
Posts
109
Karma
0
OS
Thanks for the info. The kdelibs 4.x situation is indeed not too nice. 4.2 is positively ancient! Even kf5 with 4.5+ isn't too fresh. gcc 4.5 doesn't support ranged-for, for example.

I wonder if there would be any interest in revising this every few releases. One approach could be that we aim for full compliance with and support of the last released standard by the time the next one rolls around. So, by 2014 year end, we could target full support for C++11 and by 2017, we could target full compliance with C++14, etc.

All the same, good to know the current consensus. It's tricky hard to find this info (or my google fu is just weak). Thanks, again.


karthikp, proud to be a member of KDE forums since 2008.
Image
User avatar
ivan
KDE Developer
Posts
918
Karma
14
OS
> gcc 4.5 doesn't support ranged-for

It does not support a lot of stuff. But, at least, we can pretend it does with a few Qt macros like Q_FOREACH, Q_DECL_OVERRIDE, etc.

The important ones for me are move semantic and lambdas. Others can mostly be worked-around (or lived without).

As for the applications, each one should decide which platforms it is targeting, and then decide on the allowed c++11 features. For example, Plasma went for gcc 4.5 a long time ago - it was the version in Mer (other distros were more up do date).

I hope that it will be revised for future versions, but I don't expect it to go above what Qt requires. Currently, the biggest problem is MSVC. Even if we say that we can use the newest gcc, we still need to be compilable with some agreed-upon MSVC version.


Image


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot]