I am trying to do some generic programming, in which I take an instance of some struct (which has been registered in some way) and performs a special operation with each of some subset of its members.
I have a trait that looks sort of like this:
template <typename S>
struct visitable<S, std::enable_if_t<is_visitable<S>::value>> {
template <typename V, typename T>
static void apply_visitor(V && v, T && t) {
v(t.*(get_registered_member_ptr<S>::value));
}
}
template <typename V, typename S>
void apply_visitor(V && v, S && s) {
visitable<std::remove_cv_t<std::remove_reference_t<S>>>::apply_visitor(std::forward<V>(v), std::forward<S>(s));
}
This is a simplification, actually there are going to be several member pointers and the visitor will be applied several times. But it gets to the heart of the issue.
In this code T is going to be the same type as S but with some CV / reference qualifiers, which I'm using so I don't have to type out all the overloads manually. I would like to invoke the visitor with the same value type as the expression that was passed by the user.
But when I want to apply the pointer to member, I have an issue because I can't use std::forward anymore to get the right qualifiers when I pass it to the visitor.
Is there a fancy version of std::forward that can do that, like, apply the CV and reference qualifiers of first template parameter to the second parameter and give me the result? Or should I just make one up? Or is there a better idiom for this.
Aucun commentaire:
Enregistrer un commentaire