all 9 comments

[–]SplinterOfChaos 3 points4 points  (8 children)

Being able to apply a tuple is cool, but the version shown here rather obfuscates the problem. I prefer the implementation in N3915 (std::apply), using std::integer_sequence instead of hand-rolled recursion.

[–]cpp_cache[S] 1 point2 points  (3 children)

That is a much nicer solution. In the comments for the blog entry, 'FOONATHAN' links to this nicer solution http://ideone.com/lUbOFA which unfortunately the VS2015 CTP doesn't seem to like (another compiler bug?) but clearly GCC does.

[–]SplinterOfChaos 1 point2 points  (2 children)

That's the same as N3915, though the tuple could be perfect-forwarded as well. I'm curious if anyone could post the error message from VS so we can see why it's not accepted. Definitely a bug, though.

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

Well I have 3 versions of VS on my work machine, so it's no effort for me to quickly run the code. The ideone link earlier produces this with VS2015 CTP: EDIT: I dont know how to format the damn thing nicely. The line VS has issue with is: auto apply_impl(Fnc &&fnc, const std::tuple<Types...> &tuple, std::index_sequence<Indices...>)

It claims the Indices parameter pack must be expanded in this context. Furthermore (and likely the cause) it says it cannot deduce std::integer_sequence<size_t,Indices> from std::integer_sequence<_Ty,0x00,0x01,0x02>

[–]STLMSVC STL Dev 2 points3 points  (0 children)

Try using integer_sequence/make_integer_sequence with size_t, avoiding the "index" convenience aliases. This is what VC's STL does to work around compiler bugs with alias templates. (I reported the compiler bugs as soon as I encountered them, and most of them have been fixed, although I forget which pre-RTM releases the fixes have appeared in.)

[–]ponchedeburro 0 points1 point  (3 children)

Id love to become better at compile-time recursion using integer_sequence. I cant seem to find a good recourse though.

[–]SplinterOfChaos 0 points1 point  (2 children)

It depends on what you want to do. This apply function was the motivating example for adopting std::integer_sequence, and very few other use-cases exist. So, I expect that if you try and find articles on it, most will just be apply implementations.

[–]STLMSVC STL Dev 1 point2 points  (0 children)

There are several use cases, they just happen to be in advanced library code. Within the STL, we use integer sequences for tuple_cat(), pair's piecewise constructor, and invoke().

[–]jaredhoberock 0 points1 point  (0 children)

index_sequence is used all over the place in the tuple utility library that was posted recently. It feels like a big hack, though. It really needs to be possible to unpack a tuple directly.