1e5c31af7Sopenharmony_ci// Copyright 2018 The Amber Authors.
2e5c31af7Sopenharmony_ci//
3e5c31af7Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4e5c31af7Sopenharmony_ci// you may not use this file except in compliance with the License.
5e5c31af7Sopenharmony_ci// You may obtain a copy of the License at
6e5c31af7Sopenharmony_ci//
7e5c31af7Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8e5c31af7Sopenharmony_ci//
9e5c31af7Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10e5c31af7Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11e5c31af7Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e5c31af7Sopenharmony_ci// See the License for the specific language governing permissions and
13e5c31af7Sopenharmony_ci// limitations under the License.
14e5c31af7Sopenharmony_ci
15e5c31af7Sopenharmony_ci#ifndef SRC_CAST_HASH_H_
16e5c31af7Sopenharmony_ci#define SRC_CAST_HASH_H_
17e5c31af7Sopenharmony_ci
18e5c31af7Sopenharmony_ci#include <cstddef>
19e5c31af7Sopenharmony_ci
20e5c31af7Sopenharmony_cinamespace amber {
21e5c31af7Sopenharmony_ci
22e5c31af7Sopenharmony_ci/// A hash implementation for types that can trivially be up-cast to a size_t.
23e5c31af7Sopenharmony_ci/// For example, use this as a hasher for an enum whose underlying type is
24e5c31af7Sopenharmony_ci/// an integer no wider than size_t.
25e5c31af7Sopenharmony_ci///
26e5c31af7Sopenharmony_ci/// The need for this was a defect in the C++11 library, and has been fixed
27e5c31af7Sopenharmony_ci/// in C++14.  http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
28e5c31af7Sopenharmony_citemplate <typename T>
29e5c31af7Sopenharmony_cistruct CastHash {
30e5c31af7Sopenharmony_ci  size_t operator()(const T& value) const { return static_cast<size_t>(value); }
31e5c31af7Sopenharmony_ci};
32e5c31af7Sopenharmony_ci
33e5c31af7Sopenharmony_ci}  // namespace amber
34e5c31af7Sopenharmony_ci
35e5c31af7Sopenharmony_ci#endif  // SRC_CAST_HASH_H_
36