1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include <limits> 11 #include <sstream> 12 #include <iostream> 13 #include <cassert> 14 #include <iostream> 15 16 using namespace std; 17 18 template<typename T> 19 void check_limits() 20 { 21 T minv = numeric_limits<T>::min(); 22 T maxv = numeric_limits<T>::max(); 23 24 ostringstream miniss, maxiss; 25 assert(miniss << minv); 26 assert(maxiss << maxv); 27 std::string mins = miniss.str(); 28 std::string maxs = maxiss.str(); 29 30 istringstream maxoss(maxs), minoss(mins); 31 32 T new_minv, new_maxv; 33 assert(maxoss >> new_maxv); 34 assert(minoss >> new_minv); 35 36 assert(new_minv == minv); 37 assert(new_maxv == maxv); 38 39 if(mins == "0") 40 mins = "-1"; 41 else 42 mins[mins.size() - 1]++; 43 44 maxs[maxs.size() - 1]++; 45 46 istringstream maxoss2(maxs), minoss2(mins); 47 48 assert(! (maxoss2 >> new_maxv)); 49 assert(! (minoss2 >> new_minv)); 50 } 51 52 int main(void) 53 { 54 check_limits<short>(); 55 check_limits<unsigned short>(); 56 check_limits<int>(); 57 check_limits<unsigned int>(); 58 check_limits<long>(); 59 check_limits<unsigned long>(); 60 check_limits<long long>(); 61 check_limits<unsigned long long>(); 62 } 63