#include #include #include #include #include using string = std::string; using ilist = std::list; //Place in header! template void printm(T m){ std::cout << m; } template void printlm(T m){ printm(m); printm("\n"); } int prompti(string,bool*); int prompti(string,bool*); string prompts(string,bool*); bool isneg(int); int main() { printlm("Get the number of negatives from::"); bool s {}; ilist lst {}; do { auto v = prompti("Enter an integer: ", &s); if (s) { lst.push_back(v); } } while (s); printm("Number of negatives (Defined): "); printlm(count_if(lst.cbegin(), lst.cend(), isneg)); printm("Number of negatives (Lambda): "); printlm(count_if(lst.cbegin(), lst.cend(), [] (int x) { return x < 0;})); return 0; } int prompti(string message, bool *status) { int tr {}; *status = false; std::cout << message; if (!(std::cin >> tr)){ std::cin.clear(); std::cin.ignore(); return 0; } *status = true; return tr; } double promptd(string message, bool *status) { double tr {}; *status = false; std::cout << message; if (!(std::cin >> tr)){ std::cin.clear(); std::cin.ignore(); return 0.0; } *status = true; return tr; } string prompts(string message, bool *status) { string tr {""}; *status = false; std::cout << message; if (!(std::cin >> tr)){ std::cin.clear(); std::cin.ignore(); return ""; } *status = true; return tr; } bool isneg(int x) { return x < 0; }