Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame^] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 <bitset> |
| 22 | #include <cassert> |
| 23 | #include <type_traits> |
| 24 | |
| 25 | template <std::size_t N> |
| 26 | void |
| 27 | test() |
| 28 | { |
| 29 | typedef std::bitset<N> T; |
| 30 | typedef std::hash<T> H; |
| 31 | static_assert((std::is_base_of<std::unary_function<T, std::size_t>, |
| 32 | H>::value), ""); |
| 33 | H h; |
| 34 | T bs(static_cast<unsigned long long>(N)); |
| 35 | assert(h(bs) == N); |
| 36 | } |
| 37 | |
| 38 | int main() |
| 39 | { |
| 40 | test<0>(); |
| 41 | test<10>(); |
| 42 | test<100>(); |
| 43 | test<1000>(); |
| 44 | } |