Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why don't you code in assembly?

Name: Anonymous 2012-12-30 1:55

 

Name: Anonymous 2013-01-04 18:14

>>75

template<class T, class D, class I>
T topDownBuildT(int n, D doub, I inc, T zero) {
        auto rec = [=](int x) topDownBuildT(x, doub, inc, zero);
        return n ? n&1 ? inc(rec(n-1)) : doub(rec(n/2)) : zero;
}
auto topDownBuild = [](int n, auto doub, auto inc, auto zero)
        topDownBuildT(n,doub,inc,zero);

auto bottomUpBuild = [](int n, auto doub, auto inc, auto res) {
        if (!n) return res;
        for(int i=31-__builtin_clz(n); i>=0; --i)
                res = 1&(n>>i) ? inc(doub(res)) : doub(res);
        return res;
};

#include <utility>
auto fibsFunctor = [](auto builder) {
        auto doub = [](auto p) std::make_pair(
                p.first * (2*p.second - p.first),
                p.first*p.first + p.second*p.second);
        auto inc = [](auto p) std::make_pair(p.second, p.first+p.second);
        auto zero = std::make_pair(0,1);
        return [=](int n) builder(n, doub, inc, zero);
};

auto fibs_t = fibsFunctor(topDownBuild);
auto fibs_b = fibsFunctor(bottomUpBuild);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List