#include <limits> 
#include <type_traits> 

template<typename T, typename Callable> 
void foreach_int(Callable call) 
{ 
  static_assert(std::is_integral<T>::value, "T has to be an integral type"); 
  T t = std::numeric_limits<T>::min(); 
  while(1) 
  { 
    call(t); 
    if(t == std::numeric_limits<T>::max()) break; 
    ++t; 
  } 
} 

#include <iostream> 
int main() 
{ 
  foreach_int<char>([](char val){ std::cout << (int)val << std::endl; }); 
  return 0; 
}