Ratio: mergre from trunk: fixes #7075

[SVN r79367]
This commit is contained in:
Vicente J. Botet Escriba 2012-07-08 19:58:09 +00:00
parent 55cf063bfe
commit 4778b0d7fb
4 changed files with 79 additions and 21 deletions

View File

@ -1596,6 +1596,14 @@ The specialization relays on the __ratio_greater_equal template class.
[section:history Appendix A: History]
[/==================================]
[section [*Version 1.0.3, August 1, 2012 - 1.51] ]
[*Fixes:]
* [@http://svn.boost.org/trac/boost/ticket/7075 #7075] Workaround for error: the type of partial specialization template parameter constant "n1" depends on another template parameter.
[endsect]
[section [*Version 1.0.2, April 1, 2012 - 1.50] ]
[*Fixes:]
@ -1611,7 +1619,6 @@ The specialization relays on the __ratio_greater_equal template class.
* Added MPL Rational Constant and the associated numeric metafunction specializations.
[endsect]
[section [*Version 1.0.0, Jan 2, 2011] ]

View File

@ -2,8 +2,8 @@
//
// Copyright Vicente J. Botet Escriba 2010
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
@ -20,6 +20,8 @@
#include <boost/mpl/aux_/config/eti.hpp>
#include <boost/mpl/aux_/config/integral.hpp>
#include <boost/mpl/aux_/config/static_constant.hpp>
#include <boost/mpl/aux_/config/dependent_nttp.hpp>
#include <boost/cstdint.hpp>
#if !defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) \
&& !defined(BOOST_MPL_PREPROCESSING_MODE) \
@ -66,29 +68,52 @@ struct gcd_c
};
namespace aux {
template< typename T1, T1 n1, bool n1_is_0, typename T2, T2 n2, bool n2_is_0 >
// Workaround for error: the type of partial specialization template parameter constant "n2"
// depends on another template parameter
// Note: this solution could be wrong for n1 or n2 = [2**63 .. 2**64-1]
#if defined(BOOST_MPL_CFG_NO_DEPENDENT_NONTYPE_PARAMETER_IN_PARTIAL_SPEC)
template< typename T1, boost::intmax_t n1, bool n1_is_0
, typename T2, boost::intmax_t n2, bool n2_is_0 >
struct gcd_aux
: gcd_aux<T2, n2, n2==0, T1, (n1 % n2), (n1 % n2)==0>
{};
template <typename T1, boost::intmax_t n1, typename T2, boost::intmax_t n2>
struct gcd_aux<T1, n1, false, T2, n2, true> : integral_c<T1, n1>
{};
template <typename T1, boost::intmax_t n1, typename T2, boost::intmax_t n2, bool C>
struct gcd_aux<T1, n1, true, T2, n2, C> : integral_c<T2, n2>
{};
#else // defined(BOOST_MPL_CFG_NO_DEPENDENT_NONTYPE_PARAMETER_IN_PARTIAL_SPEC)
template< typename T1, T1 n1, bool n1_is_0, typename T2, T2 n2, bool n2_is_0 >
struct gcd_aux
: gcd_aux<T2, n2, n2==0,
: gcd_aux<T2, n2, n2==0,
typename aux::largest_int<T1, T2>::type,
//~ T1,
//~ T1,
(n1 % n2), (n1 % n2)==0>
{};
template <typename T1, T1 n1, typename T2, T2 n2>
struct gcd_aux<T1, n1, false, T2, n2, true> : integral_c<T1, n1>
struct gcd_aux<T1, n1, false, T2, n2, true> : integral_c<T1, n1>
{};
template <typename T1, T1 n1, typename T2, T2 n2, bool C>
struct gcd_aux<T1, n1, true, T2, n2, C> : integral_c<T2, n2>
struct gcd_aux<T1, n1, true, T2, n2, C> : integral_c<T2, n2>
{};
#endif // defined(BOOST_MPL_CFG_NO_DEPENDENT_NONTYPE_PARAMETER_IN_PARTIAL_SPEC)
}
template<>
struct gcd_impl<integral_c_tag, integral_c_tag>
{
template< typename N1, typename N2 > struct apply
: abs<aux::gcd_aux< typename N1::value_type, N1::value, N1::value==0,
: abs<aux::gcd_aux< typename N1::value_type, N1::value, N1::value==0,
typename N2::value_type, N2::value, N2::value==0 > >
{
};

View File

@ -2,8 +2,8 @@
//
// Copyright Vicente J. Botet Escriba 2010
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
@ -20,6 +20,8 @@
#include <boost/mpl/aux_/config/eti.hpp>
#include <boost/mpl/aux_/config/integral.hpp>
#include <boost/mpl/aux_/config/static_constant.hpp>
#include <boost/mpl/aux_/config/dependent_nttp.hpp>
#include <boost/cstdint.hpp>
#if !defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) \
&& !defined(BOOST_MPL_PREPROCESSING_MODE) \
@ -67,28 +69,53 @@ struct lcm_c
namespace aux {
template< typename T1, T1 n1, bool n1_is_0, typename T2, T2 n2, bool n2_is_0 >
// Workaround for error: the type of partial specialization template parameter constant "n2"
// depends on another template parameter
// Note: this solution could be wrong for n1 or n2 = [2**63 .. 2**64-1]
#if defined(BOOST_MPL_CFG_NO_DEPENDENT_NONTYPE_PARAMETER_IN_PARTIAL_SPEC)
template< typename T1, boost::intmax_t n1, bool n1_is_0
, typename T2, boost::intmax_t n2, bool n2_is_0 >
struct lcm_aux
: abs<integral_c< typename aux::largest_int<T1, T2>::type,
( n1 / gcd<integral_c<T1,n1>, integral_c<T2,n2> >::value * n2 )
> >
{};
template <typename T1, boost::intmax_t n1, typename T2, boost::intmax_t n2>
struct lcm_aux<T1, n1, false, T2, n2, true> : integral_c<T2, 0>
{};
template <typename T1, boost::intmax_t n1, typename T2, boost::intmax_t n2, bool C>
struct lcm_aux<T1, n1, true, T2, n2, C> : integral_c<T1, 0>
{};
#else // defined(BOOST_MPL_CFG_NO_DEPENDENT_NONTYPE_PARAMETER_IN_PARTIAL_SPEC)
template< typename T1, T1 n1, bool n1_is_0, typename T2, T2 n2, bool n2_is_0 >
struct lcm_aux
: abs<integral_c< typename aux::largest_int<T1, T2>::type,
( n1 / gcd<integral_c<T1,n1>, integral_c<T2,n2> >::value * n2 )
( n1 / gcd<integral_c<T1,n1>, integral_c<T2,n2> >::value * n2 )
> >
{};
template <typename T1, T1 n1, typename T2, T2 n2>
struct lcm_aux<T1, n1, false, T2, n2, true> : integral_c<T2, 0>
struct lcm_aux<T1, n1, false, T2, n2, true> : integral_c<T2, 0>
{};
template <typename T1, T1 n1, typename T2, T2 n2, bool C>
struct lcm_aux<T1, n1, true, T2, n2, C> : integral_c<T1, 0>
struct lcm_aux<T1, n1, true, T2, n2, C> : integral_c<T1, 0>
{};
#endif // defined(BOOST_MPL_CFG_NO_DEPENDENT_NONTYPE_PARAMETER_IN_PARTIAL_SPEC)
}
template<>
struct lcm_impl<integral_c_tag, integral_c_tag>
{
template< typename N1, typename N2 > struct apply
: abs<aux::lcm_aux< typename N1::value_type, N1::value, N1::value==0,
: abs<aux::lcm_aux< typename N1::value_type, N1::value, N1::value==0,
typename N2::value_type, N2::value, N2::value==0 > >
{
};

View File

@ -13,5 +13,4 @@
#ifdef BOOST_RATIO_EXTENSIONS
#include <boost/ratio/mpl/rational_constant.hpp>
#endif
#endif // BOOST_RATIO_INCLUDE_HPP