#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <numeric>
class DecrementorGen {
int current;
public:
DecrementorGen(int current) : current(current) {}
int operator()() {
return current--;
}
};
int main()
{
std::vector<int> v(25-21);
generate(v.begin(), v.end(), DecrementorGen(25));
std::cout << accumulate(v.begin(), v.end(), 1, std::multiplies<int>()) << std::endl;
}
// A big type to hold factorial result
typedef unsigned long long bignum_t;
// Recursive template meta-function to calculate factorial at compile time
template <unsigned short N>
struct Factorial
{
static bignum_t const value = N * Factorial<N - 1>::value;
};
// Specialized template meta-function to end recursion
template <>
struct Factorial<1>
{
static bignum_t const value = 1;
};
int main()
{
// This is calculated at compile time so there is no runtime cost
bignum_t num = Factorial<10>::value; // Example for 10 (num == 3628800)
return 0;
}
Title | # Comments | Views | Activity |
---|---|---|---|
sorting efficency of sorting algorithm | 30 | 81 | |
jQuery animation faster | 1 | 17 | |
angular2 Release injecting from one Constructor to another. | 4 | 26 | |
Javascript generate change location | 12 | 25 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
19 Experts available now in Live!