Created
April 23, 2018 09:59
-
-
Save rhizoome/843863d29a2d9a48529e9a45abd841d8 to your computer and use it in GitHub Desktop.
Cool cpp
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 <vector> | |
#include <numeric> | |
struct sum_f | |
{ | |
template<class T, class U> | |
auto operator()(T x, U y) const | |
{ | |
auto p = x * y; | |
return x + y + p; | |
} | |
}; | |
constexpr auto sum = sum_f(); | |
int main() | |
{ | |
std::vector<int> v = { 1, 2, 3 }; | |
int total = std::accumulate(v.begin(), v.end(), 0, sum); | |
std::vector<float> w = { 1, 2, 3 }; | |
int ftotal = std::accumulate(w.begin(), w.end(), 0, sum); | |
std::vector<char> x = { 1, 2, 3 }; | |
int xtotal = std::accumulate(x.begin(), x.end(), 0, sum); | |
return total + ftotal + xtotal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment