Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame^] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <functional> |
| 11 | |
| 12 | // template <class T> |
| 13 | // struct hash |
| 14 | // : public unary_function<T, size_t> |
| 15 | // { |
| 16 | // size_t operator()(T val) const; |
| 17 | // }; |
| 18 | |
| 19 | // Not very portable |
| 20 | |
| 21 | #include <string> |
| 22 | #include <cassert> |
| 23 | #include <type_traits> |
| 24 | |
| 25 | template <class T> |
| 26 | void |
| 27 | test() |
| 28 | { |
| 29 | typedef std::hash<T> H; |
| 30 | static_assert((std::is_base_of<std::unary_function<T, std::size_t>, |
| 31 | H>::value), ""); |
| 32 | H h; |
| 33 | std::string g1 = "1234567890"; |
| 34 | std::string g2 = "1234567891"; |
| 35 | T s1(g1.begin(), g1.end()); |
| 36 | T s2(g2.begin(), g2.end()); |
| 37 | assert(h(s1) != h(s2)); |
| 38 | } |
| 39 | |
| 40 | int main() |
| 41 | { |
| 42 | test<std::string>(); |
| 43 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 44 | test<std::u16string>(); |
| 45 | test<std::u32string>(); |
| 46 | #endif |
| 47 | test<std::wstring>(); |
| 48 | } |