Is it possible to create a std :: list with an initializer_list?

1

I'd like to pass a temporary std::list to a function, but I do not know if it's possible to do so. I know it is possible to pass% temporary% with std::vector :

#include <iostream>
#include <vector>

template<typename T>
void mostra(const std::vector<T>& myVec)
{
    for(T var : myVec)
        std::cout << var << "\n";
}

int main()
{
    mostra<int>({12, 14, 28, 7, 10});
    return 0;
}
    
asked by anonymous 11.09.2014 / 21:18

1 answer

1

It works for me:

#include <iostream>
#include <list>

template<typename T>
void mostra(const std::list<T>& myList)
{
    for(T var : myList)
        std::cout << var << "\n";
}

int main()
{
    mostra<int>({12, 14, 28, 7, 10});
    return 0;
}
    
11.09.2014 / 21:23