代码之家  ›  专栏  ›  技术社区  ›  Konrad

构造关联容器

  •  0
  • Konrad  · 技术社区  · 14 年前

    例如,

    std::set< int > _set = { 2, 3, 5 };
    

    事实并非如此,但我想知道是否有其他方法可以像这样在构造函数中批量初始化容器?

    2 回复  |  直到 14 年前
        1
  •  2
  •   Björn Pollex    14 年前

    你可以用 Boost.Assign .

    std::set< int > _set = boost::assign::list_of(2)(3)(5);
    
        2
  •  0
  •   Oliver Charlesworth    14 年前

    const int x[] = { 2, 3, 5 };
    std::set<int> _set(&x[0], &x[sizeof(x)/sizeof(x[0])]);
    

    !