This file contains hidden or 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
| typedef int (*AbsTy)(int); | |
| Reduction<std::plus<int>,AbsTy,AbsTy> r(std::plus<int>(), &abs, &abs); | |
| r(-10, 5); // => 15 | |
| r(-2, -4); // => 6 |
This file contains hidden or 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
| makeTree(int,bool,std::string) => std::pair<int,std::pair<bool, std::string>> |
This file contains hidden or 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
| template <typename... Args> | |
| ???? makeTree(const Args&... args); |
This file contains hidden or 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
| // Termination case (A, B) -> std::pair<A,B> | |
| template <typename LhsTy, typename RhsTy> | |
| std::pair<LhsTy,RhsTy> makeTree(const LhsTy& lhs, const RhsTy& rhs) { | |
| return {lhs, rhs}; | |
| } | |
| template <typename Arg1, typename Arg2, typename Arg3, typename... Args> | |
| auto makeTree(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Args&... args) -> ??? | |
| { | |
| return {arg1, makeTree(arg2,arg3,args...)}; |
This file contains hidden or 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
| template <typename Arg1, typename Arg2, typename Arg3, typename... Args> | |
| auto makeTree(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Args&... args) -> | |
| std::pair<Arg1,decltype(makeTree(arg2,arg3,args...))> | |
| { | |
| return {arg1, makeTree(arg2,arg3,args...)}; | |
| } |
This file contains hidden or 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 <iostream> | |
| namespace std { | |
| template <typename T1, typename T2> | |
| ostream& operator<<(ostream& out, const pair<T1,T2>& p) { | |
| return out << "(" << p.first << "," << p.second << ")"; | |
| } | |
| } // end std namespace | |
| int main(int argc, char* argv[]) { |
This file contains hidden or 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
| template <size_t N> struct uint_{ }; | |
| template <size_t N, typename Lambda, typename IterT> | |
| inline void unroller(const Lambda& f, const IterT& iter, uint_<N>) { | |
| unroller(f, iter, uint_<N-1>()); | |
| f(iter + N); | |
| } | |
| template <typename Lambda, typename IterT> | |
| inline void unroller(const Lambda& f, const IterT& iter, uint_<0>) { |
This file contains hidden or 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
| std::vector<double> vec(N); | |
| // loop body as a lambda | |
| auto body = [&](const int& i) { vec[i] = i*(i-1)*4*(i+1); }; | |
| assert(vec.size()%UnrollFact == 0 && "Vector size must be divisible by the Unrolling Factor"); | |
| auto start = std::chrono::system_clock::now(); | |
| for(size_t i = 0, size=vec.size(); i!=size; i+=UnrollFact) { | |
| unroller( body, i, uint_<UnrollFact-1>() ); |
This file contains hidden or 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
| auto start = std::chrono::system_clock::now(); | |
| for(size_t i = 0, size=vec.size(); i!=size; ++i) { | |
| vec[i] = i*(i-1)*4*(i+1); | |
| } | |
| auto end = std::chrono::system_clock::now(); |
This file contains hidden or 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
| namespace detail { | |
| template <class IterT> | |
| IterT partition(IterT begin, IterT end) { | |
| // The pivot is the first element of this array section | |
| IterT pivotIdx = begin; | |
| auto pivot = *(begin++); | |
| while(begin < end){ |