1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===// 2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// 3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant// The LLVM Compiler Infrastructure 4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// 5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open 6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details. 7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// 8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===// 9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// <functional> 11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 12bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// template <class T> 13bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// struct hash 14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// : public unary_function<T, size_t> 15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// { 16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// size_t operator()(T val) const; 17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// }; 18bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 19bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// Not very portable 20bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 21bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <functional> 22bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cassert> 23bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <type_traits> 24bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <limits> 25bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cmath> 26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnanttemplate <class T> 28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid 29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnanttest() 30bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{ 31bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant static_assert((std::is_base_of<std::unary_function<T, std::size_t>, 32bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::hash<T> >::value), ""); 33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::hash<T> h; 34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t t0 = h(0.); 35bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t tn0 = h(-0.); 36bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t tp1 = h(0.1); 37bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t t1 = h(1); 38bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t tn1 = h(-1); 39bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t pinf = h(INFINITY); 40bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::size_t ninf = h(-INFINITY); 41bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t0 == tn0); 42bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t0 != tp1); 43bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t0 != t1); 44bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t0 != tn1); 45bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t0 != pinf); 46bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t0 != ninf); 47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 48bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(tp1 != t1); 49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(tp1 != tn1); 50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(tp1 != pinf); 51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(tp1 != ninf); 52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t1 != tn1); 54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t1 != pinf); 55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(t1 != ninf); 56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(tn1 != pinf); 58bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(tn1 != ninf); 59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 60bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(pinf != ninf); 61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant} 62bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 63bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main() 64bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{ 65bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<float>(); 66bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<double>(); 67bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<long double>(); 68bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant} 69