Namespaces
Variants
Views
Actions

std::initializer_list::initializer_list

From cppreference.com
< cpp‎ | utility‎ | initializer list
Revision as of 21:08, 17 August 2013 by Cubbi (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
initializer_list();
(since C++11)
(until C++14)
constexpr initializer_list();
(since C++14)

Constructs an empty initializer list.

Contents

[edit] Parameters

(none)

[edit] Exceptions

noexcept specification:  
noexcept
  

[edit] Complexity

Constant

[edit] Example

#include <iostream>
#include <initializer_list>
 
int main() 
{
    std::initializer_list<int> empty_list;
    std::cout << "empty_list.size(): " << empty_list.size() << '\n';
 
    // create initializer lists using list-initialization
    std::initializer_list<int> digits {1, 2, 3, 4, 5};
    std::cout << "digits.size(): " << digits.size() << '\n';
 
    // special rule for auto means 'fractions' has the
    // type std::initializer_list<double>
    auto fractions = {3.14159, 2.71828};
    std::cout << "fractions.size(): " << fractions.size() << '\n';
}

Output:

empty_list.size(): 0
digits.size(): 5
fractions.size(): 2

[edit] Notes

Despite a lack of constructors, it is possible to create non-empty initializer lists. Instances of std::initializer_list are implicitly constructed when: