Skip to content

Commit

Permalink
Create ex3_21_generics_version
Browse files Browse the repository at this point in the history
To replace ex3_21.cpp 
This one is generics version using template, for general version please check @pezy's code.
  • Loading branch information
Mooophy committed Sep 4, 2014
1 parent 523d1d4 commit c6319be
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ch03/ex3_21_generics_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//!
//! @author Yue Wang
//! @date 4th Sep 2014
//!

#include <iostream>
#include <vector>

/**
* @brief check
* @param first
* @param last
*
* generics version for ex3.21
*/
template<typename Iter>
void check(Iter first, Iter last)
{
for(auto it = first; it != last; ++it)
std::cout << *it << "\n";

std::cout << "size = " << last - first << "\n\n";
}

int main()
{
std::vector<int> v1;
std::vector<int> v2(10);
std::vector<int> v3(10, 42);
std::vector<int> v4{10};
std::vector<int> v5{10, 42};
std::vector<std::string> v6{10};
std::vector<std::string> v7{10, "hi"};

check(v1.begin(),v1.end());
check(v2.begin(),v2.end());
check(v3.begin(),v3.end());
check(v4.begin(),v4.end());
check(v5.begin(),v5.end());
check(v6.begin(),v6.end());
check(v7.begin(),v7.end());

return 0;
}

0 comments on commit c6319be

Please sign in to comment.