简体   繁体   English

Qt是否有与Boost的assign模块相同的东西?

[英]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. 在Boost中,有一些方便的功能可以让您在一行中填充容器。

For example, list_of lets you fill a list like so. 例如, list_of允许您填写类似的列表。

#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. 在我的项目中我使用Qt并且不能使用Boost。 Is there a similarly convenient way for filling up Qt's containers at the point of construction? 有没有一种同样方便的方法来填充Qt的容器在施工点?

您可以使用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. 从版本4.8开始,Qt支持大多数容器的C ++ 11标准初始化。

http://doc.qt.digia.com/4.8-snapshot/qt4-8-intro.html http://doc.qt.digia.com/4.8-snapshot/qt4-8-intro.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM