online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <functional> #include <chrono> using std::cout; using std::function; using std::chrono::system_clock; using std::chrono::duration_cast; using std::chrono::milliseconds; double computeMean(const double start, const int cycles) { double tmp(start); for (int i = 0; i < cycles; ++i) { tmp += i; } return tmp / cycles; } template<class T> double operate(const double a, const int b, T myFunc) { return myFunc(a, b); } template<> double operate(const double a, const int b, function<double (const double, const int)> myFunc) { cout << "nontemplate called\n"; return myFunc(a, b); } int main() { double init(1), result; int increments(1E9); // start clock system_clock::time_point t1 = system_clock::now(); function<double (const double, const int)> computeMean = [&](const double init, const int increments) { double tmp(init); for (int i = 0; i < increments; ++i) { tmp += i; } return tmp / increments; }; result = operate(init, increments, computeMean); // stop clock system_clock::time_point t2 = system_clock::now(); cout << "Input: " << init << ", " << increments << ", Output: " << result << '\n'; cout << "Time elapsed: " << duration_cast<milliseconds>(t2 - t1).count() << " ms\n"; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue