Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 482 Bytes

cpp_initialization.rst

File metadata and controls

27 lines (21 loc) · 482 Bytes

Initialization

Table of Contents

Initializer lists

#include <iostream>
#include <initializer_list>

template<typename T>
decltype(auto) sum(const std::initializer_list<T> &v) {
    T s = 0;
    for (const auto &i : v) {
        s += i;
    }
    return s;
}

int main(int argc, char *argv[]) {
    sum<int>({1,2,3,4,5});
}