Krita/C++11: Difference between revisions
Miabrahams (talk | contribs) Add list of features for consideration |
Miabrahams (talk | contribs) List some features which will probably not be used |
||
Line 1: | Line 1: | ||
= General links to C++11 and Qt | = General links to about using C++11 = | ||
'''Note:''' as would be expected from those interested in hot new technology, the writers of most of these links demonstrate Silicon Valley levels of extreme optimism. Take this with a grain of salt | There have been a few links discussing mixing C++11 with Qt, and starting with Qt 5.6 C++11 support will be default. '''Note:''' as would be expected from those interested in hot new technology, the writers of most of these links demonstrate Silicon Valley levels of extreme optimism. Take this with a grain of salt: there is no such thing as a free lunch. | ||
* [http://www.ics.com/blog/qt-and-c11 ICS.com] | * [http://www.ics.com/blog/qt-and-c11 ICS.com] | ||
Line 13: | Line 13: | ||
= Particular Features = | = Particular Features = | ||
Under "drawbacks," every item should list: "Programmers will face another feature they must learn about." | |||
=== Type Inference (auto) === | === Type Inference (auto) === | ||
'''Motivation:''' | '''Motivation:''' | ||
Line 25: | Line 27: | ||
'''Recommendation:''' | '''Recommendation:''' | ||
=== | === General Initializer Lists === | ||
'''Motivation:''' | '''Motivation:''' | ||
Member Initializers | Member Initializers | ||
Line 33: | Line 35: | ||
'''Recommendation:''' | '''Recommendation:''' | ||
=== | === Lambdas === | ||
'''Motivation:''' | '''Motivation:''' | ||
Lambda expressions for slots | Lambda expressions for slots | ||
Line 58: | Line 60: | ||
'''Recommendation:''' | '''Recommendation:''' | ||
=== enum class === | |||
'''Motivation:''' | |||
'''Drawbacks:''' | |||
'''Recommendation:''' | |||
=== nullptr === | === nullptr === | ||
'''Motivation:''' | '''Motivation:''' | ||
Line 73: | Line 83: | ||
'''Motivation:''' | '''Motivation:''' | ||
'''Drawbacks:''' unique_ptr is unable to be copied, and therefore cannot be used inside Qt classes. For example QVector<std::unique_ptr> is invalid, because QVector requires its members can be copied. This makes converting to unique_ptr | '''Drawbacks:''' unique_ptr is unable to be copied, and therefore cannot be used inside Qt classes. For example QVector<std::unique_ptr> is invalid, because QVector requires its members can be copied. This makes converting to unique_ptr a bit slow, since QVector<T *> will have to be converted to std_array<unique_ptr<T*>>, and the owner will no. | ||
'''Recommendation:''' | '''Recommendation:''' | ||
Line 92: | Line 102: | ||
'''Recommendation:''' | '''Recommendation:''' | ||
== | == C++11 features mostly for template programming == | ||
Krita makes very light use of templates. These features are useful, coming across them in the code base will add complexity for new learners, and have not been necessary so far. | |||
* | * decltype | ||
* static_assert | * static_assert | ||
* std::function and std::bind | |||
* variadic templates | * variadic templates | ||
== Other C++11 features that probably cannot be used == | |||
* Threads (Qt/KDE use an incompatible threading model) | |||
* shared_ptr and weak_ptr (Relies on C++ threading model; use KisSharedPointer) | |||
* New literal types (already have QString) | |||
* Extended Unions (already have QVariant) |
Revision as of 01:52, 15 October 2015
General links to about using C++11
There have been a few links discussing mixing C++11 with Qt, and starting with Qt 5.6 C++11 support will be default. Note: as would be expected from those interested in hot new technology, the writers of most of these links demonstrate Silicon Valley levels of extreme optimism. Take this with a grain of salt: there is no such thing as a free lunch.
- ICS.com
- qt.io
- woboq.com: c++11 in Qt5
- woboq.com: c++14 in Qt5
- "C++11 lambdas are your friend"
- Warning: c++11 range-based for may be slower
- FOSDEM 2013 presentation slides
- KDAB: speed up your Qt 5 programs using C++11
- Bjarne Stroustrup's C++11 FAQ - the grand daddy
Particular Features
Under "drawbacks," every item should list: "Programmers will face another feature they must learn about."
Type Inference (auto)
Motivation:
Drawbacks:
Recommendation:
Range-based for loop
Motivation:
Drawbacks:
Recommendation:
General Initializer Lists
Motivation: Member Initializers Mixed uniform initialization
Drawbacks:
Recommendation:
Lambdas
Motivation: Lambda expressions for slots
Drawbacks:
Recommendation:
constexpr
Motivation:
Drawbacks:
Recommendation:
Override and final
Motivation:
Drawbacks:
Recommendation:
<algorithm>
Motivation:
Drawbacks:
Recommendation:
enum class
Motivation:
Drawbacks:
Recommendation:
nullptr
Motivation:
Drawbacks:
Recommendation:
Deleted and default class members
Motivation:
Drawbacks:
Recommendation:
unique_ptr
Motivation:
Drawbacks: unique_ptr is unable to be copied, and therefore cannot be used inside Qt classes. For example QVector<std::unique_ptr> is invalid, because QVector requires its members can be copied. This makes converting to unique_ptr a bit slow, since QVector<T *> will have to be converted to std_array<unique_ptr<T*>>, and the owner will no.
Recommendation:
http://thbecker.net/articles/rvalue_references/section_01.html
Move Constructors
Motivation:
Drawbacks:
Recommendation:
Reference Qualifiers
Motivation:
Drawbacks:
Recommendation:
C++11 features mostly for template programming
Krita makes very light use of templates. These features are useful, coming across them in the code base will add complexity for new learners, and have not been necessary so far.
- decltype
- static_assert
- std::function and std::bind
- variadic templates
Other C++11 features that probably cannot be used
- Threads (Qt/KDE use an incompatible threading model)
- shared_ptr and weak_ptr (Relies on C++ threading model; use KisSharedPointer)
- New literal types (already have QString)
- Extended Unions (already have QVariant)