Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1.  
  2. template<typename TKey, typename TInKey>
  3. xGame_FORCEINLINE decltype(auto) SimplifyKey(const TInKey& inKey)
  4. {
  5.     if constexpr (std::is_same_v<TKey, TInKey>)
  6.     {
  7.         return inKey;
  8.     }
  9.     else
  10.     {
  11.         decltype(auto) key = xGame_SimplifyKey(inKey);
  12.         typedef std::decay_t<decltype(key)> SimpleKeyType;
  13.  
  14.         if constexpr (std::is_same_v<SimpleKeyType, TKey>)
  15.         {
  16.             return key;
  17.         }
  18.         else
  19.         {
  20.             if constexpr (std::is_trivial_v<TKey> &&
  21.                 std::is_convertible_v<SimpleKeyType, TKey>)
  22.             {
  23.                 return static_cast<TKey>(key);
  24.             }
  25.             else
  26.             {
  27.                 static_assert(
  28.                     std::is_same_v<MP::KeyClass<SimpleKeyType>, MP::KeyClass<TKey>>,
  29.                     "Lookup key and table key must be in the same key class. "
  30.                     "Use the xGame_Ext_SimplifyKey or xGame_Ext_KeyClass extension "
  31.                     "points to enable heterogeneous lookup for your types.");
  32.  
  33.                 return key;
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement