[MPL] Integral constant expressions and MSVC.

Morning, all. I'm trying to implement a compile-time greatest common divisor metafunction, a key component of which is boost::mpl::modulus_c. Am I correct if I say that the following is typical usage of this class template? #include <iostream> #include <boost/mpl/modulus.hpp> int main() { typedef typename boost::mpl::modulus<int,14,6>::type remainder_type; std::cout << "The remainder of 14 divided by 6 is "; std::cout << remainder_type::value << std::endl; return 0; } MinGW 3.2 accepts this usage, but MSVC 7.1 files the following complaint: ..\..\Libraries\boost\boost\mpl\modulus.hpp(39) : error C2975: 'N' : invalid template argument for 'boost::mpl::integral_c', compile-time evaluatable constant expression expected It seems MSVC doesn't recognize A % B as an integral constant expression. What's the proper way of handling this? Cromwell Enage __________________________________ Do you Yahoo!? Yahoo! Domains � Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer

Cromwell Enage writes:
Morning, all.
Hi Cromwell,
I'm trying to implement a compile-time greatest common divisor metafunction,
This one already exists in Boost, although its location is somewhat unexpected; please take a look at math/common_factor library, http://www.boost.org/libs/math/doc/common_factor.html.
a key component of which is boost::mpl::modulus_c. Am I correct if I say that the following is typical usage of this class template?
#include <iostream> #include <boost/mpl/modulus.hpp>
int main() { typedef typename ^^^^^^^^
'typename' is not allowed outside of templates.
boost::mpl::modulus<int,14,6>::type ^^^^^^^
I suppose you meant 'modulus_c', here.
remainder_type;
std::cout << "The remainder of 14 divided by 6 is"; std::cout << remainder_type::value << std::endl;
return 0; }
MinGW 3.2 accepts this usage, but MSVC 7.1 files the following complaint:
..\..\Libraries\boost\boost\mpl\modulus.hpp(39) : error C2975: 'N' : invalid template argument for 'boost::mpl::integral_c', compile-time evaluatable constant expression expected
It seems MSVC doesn't recognize A % B as an integral constant expression.
Hmm, if I make the above fixes, it compiles fine for me. May be the problem disappeared when you reduced the code for the post?
What's the proper way of handling this?
Fixing the library, which I'll happily do if we can reproduce the issue. -- Aleksey Gurtovoy MetaCommunications Engineering

--- Aleksey Gurtovoy <agurtovoy@meta-comm.com> wrote:
This one already exists in Boost, although its location is somewhat unexpected; please take a look at math/common_factor library,
http://www.boost.org/libs/math/doc/common_factor.html. Oh, good! I should learn to use boost.org's internal Google engine more.
'typename' is not allowed outside of templates.
Oops.
boost::mpl::modulus<int,14,6>::type ^^^^^^^
I suppose you meant 'modulus_c', here.
Yes, I did. Some waiting errands preoccupied my focus or I would have caught these mistakes.
It seems MSVC doesn't recognize A % B as an integral constant expression.
Hmm, if I make the above fixes, it compiles fine for me. May be the problem disappeared when you reduced the code for the post?
That it did, at least when I made the corrections from your post.
What's the proper way of handling this?
Fixing the library, which I'll happily do if we can reproduce the issue.
Now that I know Boost already has a compile-time gcd metafunction, I don't need to write my own, but FWIW, I've attached the offending code to this post. Cromwell Enage __________________________________ Do you Yahoo!? Yahoo! Domains � Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer
participants (2)
-
Aleksey Gurtovoy
-
Cromwell Enage