Created
October 13, 2014 09:27
-
-
Save KrzaQ/4e1afd16e72f41ed37b6 to your computer and use it in GitHub Desktop.
Default example cpp by kq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <cstdint> | |
#include <ctime> | |
#include <algorithm> | |
#include <deque> | |
#include <functional> | |
#include <iomanip> | |
#include <iostream> | |
#include <list> | |
#include <map> | |
#include <random> | |
#include <set> | |
#include <sstream> | |
#include <string> | |
#include <thread> | |
#include <utility> | |
using namespace std; | |
#define DBG(x) { cout << left << setw(50) << #x << boolalpha << (x) << endl; } | |
#include <boost/algorithm/string/join.hpp> | |
#include <boost/range/adaptor/transformed.hpp> | |
template<typename T, | |
typename=typename enable_if<!is_same<typename decay<decltype(*begin(declval<T>()))>::type,char>::value,int>::type> | |
auto operator<<(ostream& o, T&& t) -> decltype((begin(t),end(t),declval<ostream>()))&; | |
template<typename T> | |
typename remove_reference<T>::type const& | |
as_const(T&& t); | |
string operator "" _s(char const* msg, size_t size){ | |
return string(msg, size); | |
} | |
int main() | |
{ | |
vector<int> x{1,3,3,7}; | |
DBG(x); | |
} | |
template<typename T, | |
typename=typename enable_if<!is_same<typename decay<decltype(*begin(declval<T>()))>::type,char>::value,int>::type> | |
auto operator<<(ostream& o, T&& t) -> decltype((begin(t),end(t),declval<ostream>()))&{ | |
using boost::adaptors::transformed; | |
using boost::algorithm::join; | |
typedef typename decay<decltype(*begin(t))>::type value_type; | |
// auto f = static_cast<string(*)(typename decay<decltype(*begin(t))>::type)>(std::to_string); | |
// auto f = [](auto in) -> string { return to_string(in); }; | |
auto f = [](value_type in) { stringstream s; s << in; return s.str(); }; | |
o << "{ " | |
<< join(t | transformed(f), ", ") | |
<< "}"; | |
return o; | |
} | |
template<typename T> | |
typename remove_reference<T>::type const& | |
as_const(T&& t){ | |
return t; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment