Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Problem solved: forward variable number of arguments precisely to a template method Date: Wed, 18 Sep 2019 08:22:21 -0700 Organization: A noiseless patient Spider Lines: 28 Message-ID: <86ftkt4ok2.fsf@linuxsc.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="d7421874ff1696044f351dbc5e408957"; logging-data="28854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BXuyTHxVD3VfmOIPpcNDzkfYr0FJeUGA=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:9Dkd+nnz+Ld4okLPGm5n3rSX/7k= sha1:sdhN6HgemyBdzfmh5uhq7gMjYZ4= Xref: csiph.com comp.lang.c++:68500 Pavel writes: > I just realized the problem was solved (not by me but by a high-class > C++ expert who is a colleague of mine, to my luck). The below solution > works with gcc 4.8.5. The key is to apply "Identity" pattern to the > variable parameter type list and provide more information for type > deduction. [...] > > [ and the key part is ] > > template > struct Identity { > using type = T; > }; > > template > struct Caller { > Caller(T& to): o(to) {} > T& o; > template > void callMethod(void (T::*m)(A...), typename Identity::type... args) { > (o.*m)(args...); > } > }; Interesting. It took me a while to figure out what's going on and why this works. At first it looked exactly backwards, but in retrospect it makes sense. Kudos to your colleague.