Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- void doStuff(int* i) { }
- template<typename... Args>
- struct Consumer {
- virtual void ConsumeImpl(Args*... args) {
- doStuff(*args...);
- }
- template<typename... Args1>
- void Consume(Args1&&... args) {
- ConsumeImpl(&args...);
- }
- };
- template<typename... Args>
- void forwardToConsumer(Args&&... args) {
- Consumer<typename std::decay<Args>::type...> p;
- p.Consume(std::forward<Args>(args)...);
- }
- int main() {
- int i = 1;
- int * const iPtr = &i;
- // This does not compile. Error:
- // foo.cc: In instantiation of ‘void Consumer<Args>::Consume(Args1&& ...) [with Args1 = {int* const&}; Args = {int*}]’:
- // foo.cc:21:3: required from ‘void forwardToConsumer(Args&& ...) [with Args = {int* const&}]’
- // foo.cc:29:25: required from here
- // foo.cc:14:5: error: invalid conversion from ‘int* const*’ to ‘int**’ [-fpermissive]
- // foo.cc:8:16: error: initializing argument 1 of ‘void Consumer<Args>::ConsumeImpl(Args* ...) [with Args = {int*}]’ [-fpermissive]
- forwardToConsumer(iPtr);
- }
Advertisement
Add Comment
Please, Sign In to add comment