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