Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
(non?)-template template parameters for container stream insertion
// Can https://stackoverflow.com/a/14311714 be reasonably rewritten with only // non-template template parameters? (Try 1: overload resolution is a problem.) #include <iostream> #include <vector> #include <deque> #include <list> #define USE_TEMPLATE_TEMPLATE_PARAMETER_VERSION false #if USE_TEMPLATE_TEMPLATE_PARAMETER_VERSION template<typename T, template<class,class...> class C, class... Args> std::ostream& operator <<(std::ostream& os, const C<T,Args...>& objs) { os << __PRETTY_FUNCTION__ << '\n'; for (auto const& obj : objs) os << obj << ' '; return os; } #else template<typename Container> std::ostream& operator <<(std::ostream& os, const Container& objs) { os << __PRETTY_FUNCTION__ << '\n'; for (auto const& obj : objs) os << obj << ' '; return os; } #endif int main() { std::vector<float> vf { 1.1, 2.2, 3.3, 4.4 }; std::cout << vf << '\n'; std::list<char> lc { 'a', 'b', 'c', 'd' }; std::cout << lc << '\n'; std::deque<int> di { 1, 2, 3, 4 }; std::cout << di << '\n'; return 0; }
run
|
edit
|
history
|
help
0
10226
Enum flags operator example
sort
C++ does not have reference-to-reference types
Composite pattern
Magic, why 1 2?
selection sort
10 naturalnumbers
__FUNCTION__ not a preprocessor macro on clang
my override