1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
namespace impl
{
template < typename T > inline void do_print( const T& v, std::ostream& stm )
{ stm << v << ' ' ; }
template < typename F, typename S > // print pair
inline void do_print( const std::pair<F,S>& p, std::ostream& stm )
{ stm << '{' << p.first << ',' << p.second << "} " ; }
}
template < typename... ARGS, template < typename... ARGS > class SEQ > // print for standard contaners
void print( const SEQ<ARGS...>& seq, std::ostream& stm = std::cout,
typename SEQ<ARGS...>::iterator* = 0 )
{ stm << "[ " ; for( const auto& v : seq ) impl::do_print(v,stm) ; stm << "]\n" ; }
// overload for C-style array
template < typename T, std::size_t N >
void print( T (&seq)[N], std::ostream& stm = std::cout )
{ stm << "[ " ; for( const auto& v : seq ) impl::do_print(v,stm) ; stm << "]\n" ; }
#include <array> // overload for std::array
template < typename T, std::size_t N >
void print( const std::array<T,N>& seq, std::ostream& stm = std::cout )
{ stm << "[ " ; for( const auto& v : seq ) impl::do_print(v,stm) ; stm << "]\n" ; }
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
int main()
{
{ int seq[] { 1, 2, 3, 4 } ; print(seq) ; }
{ std::array<int,4> seq{ { 1, 2, 3, 4 } } ; print(seq) ; }
{ std::vector<int> seq{ 1, 2, 3, 4 } ; print(seq) ; }
{ std::deque<int> seq{ 1, 2, 3, 4 } ; print(seq) ; }
{ std::list<int> seq{ 1, 2, 3, 4 } ; print(seq) ; }
{ std::set<int> seq{ 1, 2, 3, 4 } ; print(seq) ; }
{ std::multiset<int> seq{ 1, 2, 3, 1, 2, 4 } ; print(seq) ; }
{ std::unordered_set<int> seq{ 1, 2, 3, 4 } ; print(seq) ; }
{ std::unordered_multiset<int> seq{ 1, 2, 3, 1, 2, 4 } ; print(seq) ; }
{ std::map<int,int> seq{ {1, 0}, {2, 3}, {4, 5} } ; print(seq) ; }
{ std::multimap<int,int> seq{ {1, 0}, {2, 3}, {4, 5}, {2,8} } ; print(seq) ; }
{ std::unordered_map<int,int> seq{ {1, 0}, {2, 3}, {4, 5} } ; print(seq) ; }
{ std::unordered_multimap<int,int> seq{ {1, 0}, {2, 3}, {4, 5}, {2,8} } ; print(seq) ; }
}
|