In Boost there are some convenient functions that let you fill up a container in a single line.
For example, list_of lets you fill a list like so.
#include <boost/assign/list_of.hpp> // for 'list_of()'
#include <list>
std::list<int> primes = boost::assign::list_of(2)(3)(5)(7)(11);
On my project I'm using Qt and cannot use Boost. Is there a similarly convenient way for filling up Qt's containers at the point of construction?
You can use QList::operator<<
QList<int> primes = QList<int>() << 2 << 3 << 5 << 7 << 11;
From version 4.8 Qt supports the C++11 standard initialization for most containers.
http://doc.qt.digia.com/4.8-snapshot/qt4-8-intro.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With