Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Qt have anything equivalent to Boost's assign module?

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?

like image 684
Tim MB Avatar asked Nov 13 '12 12:11

Tim MB


2 Answers

You can use QList::operator<<

QList<int> primes = QList<int>() << 2 << 3 << 5 << 7 << 11;
like image 101
Kamil Klimek Avatar answered Nov 11 '22 03:11

Kamil Klimek


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

like image 6
Šimon Tóth Avatar answered Nov 11 '22 05:11

Šimon Tóth