I'm trying to implement a trait-based policy subsystem and I have an issue which I don't really know how to tackle (if it's even possible). I have a traits that looks like this:
template <typename ValueT, typename TagT = void, typename EnableT = void>
struct TPolicyTraits
{
static void Apply(ValueT& value) { }
};
And this trait can be specialized as such:
struct MyPolicy {};
template <typename ValueT>
struct TPolicyTraits<ValueT, MyPolicy>
{
static void Apply(ValueT& value) { /* Implementation */ }
};
I would like to register policy at compile time in a sort of linked list. The policy system would be used like this:
namespace PolicyTraits
{
template <typename ValueT, typename TagT>
using TPolicyTraitsOf = TPolicyTraits<std::decay_t<ValueT>, TagT>;
template <typename ValueT>
void Apply(ValueT& value)
{
// todo iterate through constexpr tag list and apply policies
}
template <typename TagT>
constexpr void Enable()
{
// todo add tag to constexpr list
}
}
int main()
{
PolicyTraits::Enable<MyPolicy>();
PolicyTraits::Apply(std::string());
}
Is there any way to achieve this?
Aucun commentaire:
Enregistrer un commentaire