Home Dashboard Directory Help
Search

std::ratio arithmetic classes not working as specified. by Wyck


Status: 

Active


1
0
Sign in
to vote
Type: Bug
ID: 786967
Opened: 5/15/2013 5:45:44 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Tried to compile the following code:

#include <iostream>
#include <ratio>

int main()
{
    typedef std::ratio<2, 3> two_third;
    typedef std::ratio<1, 6> one_sixth;

    typedef std::ratio_add<two_third, one_sixth> sum;
    std::cout << "2/3 + 1/6 = " << sum::num << '/' << sum::den << '\n';
}

But I get the following error:

error C2039: 'num' : is not a member of 'std::ratio_add<_R1,_R2>'

According to the standard, and all the C++11 examples out there, sum::num and sum::den should be defined. Instead it is necessary to write: sum::type::num and sum::type::den.

The std::ratio class works correctly in that it has the declarations of num and den. So in the example above, one could safely write: two_third::num and two_third::den, but the arithmetic classes: ratio_add, ratio_subtract, ratio_multiply, and ratio_divide, lack the declarations of num and den. Seems like it's just missing those declarations in the <ratio> header file.


Full error list:

1>------ Build started: Project: ConsoleApplication13, Configuration: Debug Win32 ------
1> Main.cpp
1>e:\dev\test\consoleapplication13\main.cpp(10): error C2039: 'num' : is not a member of 'std::ratio_add<_R1,_R2>'
1>         with
1>         [
1>             _R1=two_third,
1>             _R2=one_sixth
1>         ]
1>e:\dev\test\consoleapplication13\main.cpp(10): error C2065: 'num' : undeclared identifier
1>e:\dev\test\consoleapplication13\main.cpp(10): error C2039: 'den' : is not a member of 'std::ratio_add<_R1,_R2>'
1>         with
1>         [
1>             _R1=two_third,
1>             _R2=one_sixth
1>         ]
1>e:\dev\test\consoleapplication13\main.cpp(10): error C2065: 'den' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Details
Sign in to post a comment.
Posted by Microsoft on 7/1/2013 at 4:15 PM
Hi again,

We've announced that alias templates will be supported in VS 2013 RTM (but not Preview). I've just checked in the corresponding STL changes. For more information, please read my VCBlog post: http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx

Reminder: 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
stl@microsoft.com
Posted by Microsoft on 5/17/2013 at 1:59 PM
Hi,

Thanks for reporting this bug. This is currently by design, because while the Standard specifies ratio_add as an alias template, our compiler hasn't implemented alias templates yet. Therefore, our STL implementation is imperfectly simulating alias templates with nested typedefs:

C:\Temp>type meow.cpp
#include <iostream>
#include <ratio>
using namespace std;

int main() {
#ifdef _MSC_VER
    typedef ratio_add<ratio<2, 3>, ratio<1, 6>>::type sum;
#else
    typedef ratio_add<ratio<2, 3>, ratio<1, 6>> sum;
#endif

    cout << sum::num << "/" << sum::den << endl;
}

C:\Temp>cl /EHsc /nologo /W4 /MTd meow.cpp
meow.cpp

C:\Temp>meow
5/6

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
stl@microsoft.com
Posted by Microsoft on 5/15/2013 at 10:09 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 5/15/2013 at 5:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
UploadSummary-130515124534.xml (restricted) 5/15/2013 -
VsInfo.xml (restricted) 5/15/2013 -
DxDiagOutput.txt (restricted) 5/15/2013 -
SolutionFingerprint.3648.html (restricted) 5/15/2013 -