Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
non-template template parameters for container stream insertion: SFINAE
// Can https://stackoverflow.com/a/14311714 be reasonably rewritten with only // non-template template parameters? (Try 2: SFINAE on the return type works.) #include <deque> #include <iostream> #include <list> #include <string> // Neither version shown in this file works with std::string. #include <vector> #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> auto operator <<(std::ostream& os, const Container& objs) -> decltype(os << *objs.begin()) { os << __PRETTY_FUNCTION__ << '\n'; for (auto const& obj : objs) os << obj << ' '; return os; } #endif int main() // also from SO post, but modified somewhat { std::cout << "Hello, world!" << '\n'; 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'; std::string s ("Goodbye!"); //std::cout << s << '\n'; // doesn't work }
run
|
edit
|
history
|
help
0
Example of custom deleter to manage a resource.
Arduino Bluetooth Periodiek Systeem
user defined exception
Example Node Program
Test bitfields with unnamed union
Move Construction
numeric_limits
pointer to complete array does not convert implicitly to pointer to array of unknown bound
Code Rush Game Group 1
hw1 Os