File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ /* ****************************************************************/ /* *
2+ * \file print_list.h
3+ * \brief Template function to print std::list of any types.
4+ *
5+ * \author Xuhua Huang
6+ * \date October 2021
7+ *********************************************************************/
8+
9+ #ifndef PRINT_LIST_H
10+ #define PRINT_LIST_H
11+
12+ #include < iostream>
13+ #include < list>
14+
15+ #ifndef DEBUG
16+ #define DEBUG (arg_str ) std::cout << arg_str << std::endl;
17+ #endif
18+
19+ namespace util {
20+ namespace list {
21+
22+ /* Template to print a std::list with O(n). */
23+ /* For sanity, using constant reference instead of iterators. */
24+ template <typename T>
25+ static void print_list (std::list<T> arg_list)
26+ {
27+ DEBUG (" \n [fn]Util::list::print_list" );
28+
29+ /* Loop through the vector with iterator. */
30+ typename std::list<T>::iterator iter; // keyword "typename" is required for iterator
31+ for (iter = arg_list.begin (); iter != arg_list.end (); ++iter)
32+ std::cout << *iter << " " ; // dereference the iterator to print content
33+
34+ DEBUG (" [fn]Finished printing the list." );
35+ return ;
36+ }
37+
38+ } // end Util::list
39+ } // end Util
40+
41+
42+ #endif
You can’t perform that action at this time.
0 commit comments