본문 바로가기

Programming/C&C++&C#

modern C++ begin/end

728x90
반응형
  • begin(), end() 함수 사용
#include <iostream>
#include <vector>
#include <list>
#include <iterator>

using namespace std;

template<typename T> void show (T& c)
{
    auto p1 = begin(c);
    auto p2 = end(c);

    while (p1 != p2)
    {
        cout << *p1 << endl;
        ++p1;
    }
}
int main()
{
    list<int> a = {1, 2, 3};
    vector<int> b = {1, 2, 3};
    int c[3] = {1, 2, 3};

    show(a);
    show(b);
    show(c);
}


반응형

'Programming > C&C++&C#' 카테고리의 다른 글

modern C++ 스마트포인터 unique_ptr  (0) 2019.12.26
modern C++ noexcept  (0) 2019.12.15
modern C++ using 사용법  (0) 2019.12.15
modern C++ static_assert  (0) 2019.12.15
modern C++ 11/14 iteral & type, auto & decltype  (0) 2019.12.15