Files
revng-revng/include/revng/ADT/KeyedObjectTraits.h
Pietro Fezzardi b4395794dd KeyedObjectTraits: drop useless template parameter
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.
2021-06-09 20:13:27 +02:00

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>);