Skip to content

Instantly share code, notes, and snippets.

@MiSawa
Last active December 17, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiSawa/5661944 to your computer and use it in GitHub Desktop.
Save MiSawa/5661944 to your computer and use it in GitHub Desktop.
#include <iostream>//{{{
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <utility>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <memory>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cassert>
#include <ctime>
#include <cctype>//}}}
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)//{{{
#define rep(i,n) REP(i,0,n)
#define repsz(i,v) rep(i,sz(v))
#define let(v, x) __typeof(x) v = (x)
#define foreach(i,v) for(let(i, (v).begin());i!=(v).end();i++)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size()) //}}}
static const int INF = 1<<25;
static const double EPS = 1e-5;
using namespace std;//{{{
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;//}}}
template<typename T> ostream& out(T b, T e, ostream& os=cout){ //{{{
for(; b != e; ++b != e && os << ", ")os << *b; return os;
}
template<class T> T mineq(T &a, const T &b){ return a = min(a, b); }
template<class T> T maxeq(T &a, const T &b){ return a = max(a, b); } //}}}
template <typename T, typename U>
struct sfinae_helper{typedef void type;};
template <typename T, typename U = void>
struct Print{ static ostream& pp(ostream& os, const T& x){ return os << x; } };
template <typename T>//Container//{{{
struct Print<T, typename sfinae_helper<T, typename T::iterator>::type>{
static ostream& pp(ostream& os, const T& x){
os << '[';
foreach(it, x) os << (it == x.begin() ? "" : " ") << *it;
return os << ']';
}
};//}}}
template <typename T>//Pair//{{{
struct Print<T, typename sfinae_helper<T, typename T::first_type>::type>{
static ostream& pp(ostream& os, const T& x){ return os << '(' << x.first << ", " << x.second; }
};//}}}
template <typename T>//has inspect()//{{{
struct Print<T, typename sfinae_helper<T, typeof(&T::inspect)>::type>{
static ostream& pp(ostream& os, const T& x){ return os << x.inspect(); }
};//}}}
namespace trace{//{{{
struct trace{
ostream& os;
trace(ostream& os): os(os) { }
template<typename T>
trace& operator<<(const T& x){ Print<T>::pp(os, x); return *this;}
trace& operator<<(ostream& f(ostream&)){ f(os); return *this; }
} tr(cout);
};//}}}
namespace no_trace{//{{{
struct no_trace{
template<typename T> no_trace& operator<<(const T& x){ return *this; }
no_trace& operator<<(ostream& f(ostream&)){ return *this; }
} tr;
};//}}}
using namespace trace;
struct MyClass{
string inspect() const { return "myclass"; }
};
struct MyClass2{
};
ostream& operator<<(ostream& os, MyClass2 myclass2){ return os << "myclass2"; }
bool solve(){
vector<int> a;
for(int i=0;i<10;i++) a.push_back(i);
tr << "hoge" << endl << a << endl; // expected output: "[0 1 2 3 4 5 6 7 8 9]"
MyClass x;
MyClass2 y;
tr << x << " " << y << endl;
return true;
}
int main(){
//cin.tie(0);
//ios_base::sync_with_stdio(0);
cout.setf(ios::fixed); cout.precision(10);
solve();
return 0;
}
// vim:set foldmethod=marker commentstring=//%s:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment