Skip to content

Instantly share code, notes, and snippets.

@hotwatermorning
Created November 15, 2017 08:07
Show Gist options
  • Save hotwatermorning/e6caf587bfe7bffa93b38606e2594d19 to your computer and use it in GitHub Desktop.
Save hotwatermorning/e6caf587bfe7bffa93b38606e2594d19 to your computer and use it in GitHub Desktop.
initializer_listもコンテナも受け付けられるようにする
#include <iostream>
#include <vector>
#include <list>
#include <initializer_list>

template <template <class...> class U = std::initializer_list, class E = int, class T = U<E>>
void f(T t)
{
    for(auto x: t) {
        std::cout << x << std::endl;
    }
}

int main()
{
    std::list<double> x { .1, .2, .3 };
    auto y = { "hello", "c++", "world" };
    
    f({1u, 2u, 3u});
    f(x);
    f(y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment