tuple_size don't work properly for classes derived from std::tuple - by PeTeeR22r

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 753773 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 7/15/2012 7:00:40 AM
Access Restriction Public


in VS2012 RC tuple_size for classes that are derived from std::tuple returns size equal to zero, in visual studio 2010 it returned size of tuple from which class is derived.
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:32 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 4/1/2013 at 11:22 AM
In VC10, our "faux variadic" preprocessor machinery had a hardcoded limit of 10. In VC11, we lowered this limit to 5 in order to improve compile times and compiler memory consumption for the majority of users, but we also made it configurable. Defining _VARIADIC_MAX to 10 project-wide will restore the old limit. Note that tuple's implementation in VC11 was kind of squirrely and will appear to accept a few arguments beyond the limit, but they will not work reliably. In VC12, all of these problems will be eradicated, as we have rewritten the STL to use real variadic templates everywhere. Thanks, STL
Posted by PeTeeR22r on 4/1/2013 at 5:26 AM

I was planing to write sooner, but I didn't have time to do that.

Nice that you resolved this issue, at least it wont compile and give bogus runtime results. I've also find some other problems with tuple under VS2012 that on VS2010 didn't occur. Tuple of size 9 and 10 don't compile any more. Tuple of size 7 and 8 do compile but give incorrect tuple size. Bellow is a test code which under VS2010 works just fine. Maybe in next VS problem don't occur after you implemented variadic templates and used them in tuple implementation. But it's worth checking.

    static_assert( tuple_size<tuple<int,int,int,int,int,int,int>>::value == 7, "error tuple of size 7" );
    static_assert( tuple_size<tuple<int,int,int,int,int,int,int,int>>::value == 8, "error tuple of size 8" );
    static_assert( tuple_size<tuple<int,int,int,int,int,int,int,int,int>>::value == 9, "error tuple of size 9" );
    static_assert( tuple_size<tuple<int,int,int,int,int,int,int,int,int,int>>::value == 10, "error tuple of size 10" );
Posted by Microsoft on 3/29/2013 at 6:01 PM
Hi again,

We had time to fix this bug, and the fix will be available in VC12, although it's not the fix you expected.

The C++ Standard requires tuple_size to work for tuple, pair, array, and cv-qualified versions of those types, but not any other types - such as classes derived from tuples, or even references to tuples. So, in addition to updating tuple_size to follow the Standard by deriving from integral_constant, we've added a static_assert that explains: "error C2338: The C++ Standard doesn't define tuple_size for this type."

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 2/21/2013 at 1:53 PM

Thanks for reporting this bug. I wanted to let you know what's happening with it. I'm still keeping track of it, but it's been resolved as "Deferred" because we may not have time to fix it in VC12. (Note: VC8 = VS 2005, VC9 = VS 2008, VC10 = VS 2010, VC11 = VS 2012.)

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries