readconfusing cp templates
Difference between en2 and en3, changed 23 character(s)
~~~~~↵
template<typename T>↵
inline void read(T &x){↵
    x = 0; T f = 1; char ch = getchar();↵
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}↵
    while (isdigit(ch))  {x = x * 10 + ch &mdash; '0'; ch = getchar();}↵
    x *= f;↵
}↵
~~~~~↵

Can anyone tell me how this template works↵

or infact any of these templates↵


~~~~~↵
template<class Fun> class y_combinator_result {↵
    Fun fun_;↵
public:↵
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}↵
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }↵
};↵
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }↵
 ↵
 ↵
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }↵
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }↵
 ↵
void dbg_out() { cerr << endl; }↵
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }↵
#ifdef NEAL_DEBUG↵
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)↵
#else↵
#define dbg(...)↵
#endif


~~~~~↵




I found these in [user:neal,2021-04-21]'s submissions

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English amrit2kbron 2021-04-21 10:08:07 23
en2 English amrit2kbron 2021-04-21 10:06:56 191
en1 English amrit2kbron 2021-04-21 10:05:54 1577 Initial revision (published)