samedi 29 juin 2019

Write the type of a pointer to member data from other template types

I have a function that extracts pointer to member type from other types, and this works:

template<class T2, class Array,
    class Element = typename std::decay_t<Array>::element,
    class PointerToMemberType = T2 Element::*
>
v f(Array&& a, PointerToMemberType pm);

However I cannot find the way to write PM, without first definining Element which can be omitted.

How can I write PointerToMemberType directly without using the auxiliary Element?

I tried plain substitution but it doesn't work:

template<
    class T2, class Array, 
    class PointerToMemberType = T2 typename std::decay_t<Array>::element::*
>
void f(Array&&, PointerToMemberType pm);
// error: expected identifier before ‘*’ token
  677 |  class PointerToMemberType = T2 typename std::decay_t<Array>::element::* 
                                                                               ^

I also tried adding typename and parenthesis in several places.

Note that PointerToMemberType is not used for deduction at the moment, although I would try to use it in the future.

In some places it recommends using std::invoke so one doesn't need to deal with pointers-to-data-members, How would that fit or simplify something here?

Aucun commentaire:

Enregistrer un commentaire