Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created January 12, 2014 01:34
Show Gist options
  • Select an option

  • Save pasberth/8379449 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/8379449 to your computer and use it in GitHub Desktop.
すべての要素を出力する
#include <string>
#include <vector>
#include <list>
#include <iostream>
template<class Iterator>
void print_all(Iterator first, Iterator last)
{
while (first != last)
{
std::cout << *first << std::endl;
++first;
}
}
int main(int argc, char const *argv[])
{
std::vector<std::string> v;
v.push_back("a");
v.push_back("b");
v.push_back("c");
print_all(v.begin(), v.end());
std::list<std::string> l;
l.push_back("a");
l.push_back("b");
l.push_back("c");
print_all(l.begin(), l.end());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment