mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
b4395794dd
The second template parameter, defaulted to void, was only used for SFINAE with enable_if. Now that all uses of enable_if are gone replaced by concepts, this parameter does not serve any purpose anymore.
38 lines
902 B
C++
38 lines
902 B
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "revng/ADT/STLExtras.h"
|
|
#include "revng/Support/Concepts.h"
|
|
|
|
template<typename T>
|
|
struct KeyedObjectTraits {
|
|
// static * key(const T &);
|
|
// static T fromKey(* Key);
|
|
};
|
|
|
|
// clang-format off
|
|
template<typename T>
|
|
concept HasKeyObjectTraits = requires(T a) {
|
|
{ KeyedObjectTraits<T>::key(a) };
|
|
{ KeyedObjectTraits<T>::fromKey(KeyedObjectTraits<T>::key(a)) } -> same_as<T>;
|
|
};
|
|
// clang-format on
|
|
|
|
/// Inherit if T is the key of itself
|
|
template<typename T>
|
|
struct IdentityKeyedObjectTraits {
|
|
static T key(const T &Obj) { return Obj; }
|
|
|
|
static T fromKey(T Obj) { return Obj; }
|
|
};
|
|
|
|
/// Trivial specialization for integral types
|
|
template<Integral T>
|
|
struct KeyedObjectTraits<T> : public IdentityKeyedObjectTraits<T> {};
|
|
|
|
static_assert(Integral<int>);
|
|
static_assert(HasKeyObjectTraits<int>);
|