I try to write a code with c++17 auto
non-type template parameter pack for class data member pointer, but the following code clang will compile and gcc will not, you can see godbolt for error message , can somebody tell me which one should I believe since I can't figure out why gcc reject this.
Thanks for you help.
template <
typename B,
template <auto B::*...> typename Wrapper,
auto B::*... Args
>
void f(Wrapper<Args...>) {}
template <auto... Args> struct Wrapper {};
struct A { int i; float f; };
// gcc error: unable to deduce 'auto B::*' from '&A::i'
f(Wrapper<&A::i, &A::f>{});
I know that if change <auto B::*...>
to <auto...>
then both can compile, but I want know why gcc couldn't deduce correct type since the following non-auto template parameter get same situation: gcc can't compile and clang can:
template <
typename B,
typename... MT,
template <MT B::*...> class Wrapper,
MT B::*... Args
>
void f(Wrapper<Args...>) {}
Try with
template <
template <auto ...> typename Wrapper,
auto ... Args
>
void f(Wrapper<Args...>) {}
auto
is an alternative for B::*
; so you should use auto
or B::*
, not both.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.