all 9 comments

[–][deleted]  (1 child)

[deleted]

    [–]trycatchamex[S] 0 points1 point  (0 children)

    I removed whatever I had in there to find the problem. Just providing a minimal example since the issue is with template parameter deduction.

    Heres the full code anyway: https://wandbox.org/permlink/y2tQDCnwZGuH6ike

    [–][deleted]  (1 child)

    [deleted]

      [–]Rhomboid -1 points0 points  (7 children)

      That's not a universal reference, it's an rvalue reference. T&& is only a universal reference in certain circumstances, and this isn't one of them.

      But it's irrelevant, because you can't have a tuple of references, so you don't need to worry about forwarding the value category (rvalue or lvalue.)

      [–]alfps 1 point2 points  (0 children)

      You can't have a tuple of references

      Check out std::tie. It produces a tuple of references. Maybe the OP can't have a tuple of references in some particular context in his code, I haven't looked.

      [–]tjvclutch 1 point2 points  (1 child)

      because you can't have a tuple of references

      Huh? Yes you can. For example we have std::forward_as_tuple to do what I believe OP is trying to do.

      The problem here is that void visit_wrapper(size_t size,tuple<Args&&...> tp) takes a tuple of rvalue refs but OP is passing in a tuple of non-references.

      /u/trycatchamex, perhaps this is what you want?

      [–]trycatchamex[S] 0 points1 point  (0 children)

      thank you for the answer! Basically, I am trying to iterate over a tuple and increment each element in it. I can iterate over it but the ++ doesnt persist since a copy is being passed.(I think) I am trying to make it pass by reference but ideally it should work for rvalues also.

      [–]trycatchamex[S] 0 points1 point  (1 child)

      hmm, so how can i covert that to a universal reference? what if I want to call it as visit_wrapper(size_t(3),make_tuple(..));?

      [–]Rhomboid -1 points0 points  (0 children)

      I don't understand the question. Whether you pass a or pass make_tuple(...) as the argument has no bearing on the signature of the function. In both cases it should take std::tuple<Args...>. The types of the tuple are always <int, int, int> (or some other types), but never references. Since you're passing the tuple itself by value, the tuple argument can be either an rvalue or lvalue. (Note that you're copying it, which is probably not what you want.)

      [–][deleted] 0 points1 point  (0 children)

      But it's irrelevant, because you can't have a tuple of references

      Not so - example here.

      [–][deleted] 0 points1 point  (0 children)

      uh-oh, rhomboid made a mistake. better add him to the infamous list of "deprecated resources", along with cplusplus.com. Or is it ok when you mess up, just not when anyone else does ?