Which greedy initializer-list examples are lurking in the Standard Library?

前端 未结 2 1265
余生分开走
余生分开走 2020-12-03 01:38

Since C++11, the Standard Library containers and std::string have constructors taking an initializer-list. This constructor takes precedence over other construc

2条回答
  •  情书的邮戳
    2020-12-03 02:40

    Just searching for the occurence of initializer_list.

    • All sequences, they are have the constructors like that of vector:

      • deque
      • dynarray
      • forward_list
      • list
      • vector
    • valarray

    • basic_string

    • Unordered collections, there is a constructor which takes an integer to determine the initial bucket count.

      • unordered_set
      • unordered_multiset

    I think that's all of it.

    #include 
    #include 
    
    int main() {
        std::unordered_set f (3);
        std::unordered_set g {3};
        std::cout << f.size() << "/" << g.size() << std::endl; // prints 0/1.
    }
    

提交回复
热议问题