#include <iostream>
#include <array>
#include <limits>
#include <iterator>
#include <algorithm>

template<typename T, typename Q, typename E>
T askForOne(std::ostream & out, std::istream & in, Q&& question, E&& error) {
  T value;
  out << question;
  while (not (in >> value)) {
    in.clear();
    in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    out << error;
  }
  return value;
}


template<typename T, std::size_t N, typename Q, typename E>
std::array<T, N> askFor(std::ostream & out, std::istream & in, Q&& question, E&& error) {
  std::array<T, N> values;
  auto const scan = [&in, &values] {
    for (auto & value : values) {
      if (not (in >> value)) {
        return false;
      }
    }
    return true;
  };
  out << question;
  while (not scan()) {
    in.clear();
    in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    out << error;
  }
  return values;
}


int main(int, char **) {
  using namespace std;
  int one = askForOne<int>(cout, cin, "Int? ", "Meh. ");
  int two = askForOne<int>(cout, cin, "Int? ", "Meh. ");
  auto ints = askFor<int, 5>(cout, cin, "5 ints? ", "Meh. ");
  cout << "one = " << one << endl;
  cout << "two = " << two << endl;
  cout << "ints = ";
  copy(begin(ints), end(ints), ostream_iterator<int>{cout, ", "});
  return 0;
}
