Chris@102: // Boost common_factor_ct.hpp header file ----------------------------------// Chris@102: Chris@102: // (C) Copyright Daryle Walker and Stephen Cleary 2001-2002. Chris@102: // Distributed under the Boost Software License, Version 1.0. (See Chris@102: // accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: // See http://www.boost.org for updates, documentation, and revision history. Chris@102: Chris@102: #ifndef BOOST_INTEGER_COMMON_FACTOR_CT_HPP Chris@102: #define BOOST_INTEGER_COMMON_FACTOR_CT_HPP Chris@102: Chris@102: #include // self include Chris@102: #include // for BOOST_STATIC_CONSTANT, etc. Chris@102: Chris@102: namespace boost Chris@102: { Chris@102: namespace integer Chris@102: { Chris@102: Chris@102: // Implementation details --------------------------------------------------// Chris@102: Chris@102: namespace detail Chris@102: { Chris@102: // Build GCD with Euclid's recursive algorithm Chris@102: template < static_gcd_type Value1, static_gcd_type Value2 > Chris@102: struct static_gcd_helper_t Chris@102: { Chris@102: private: Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, new_value1 = Value2 ); Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, new_value2 = Value1 % Value2 ); Chris@102: Chris@102: #ifndef __BORLANDC__ Chris@102: #define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast(Value) Chris@102: #else Chris@102: typedef static_gcd_helper_t self_type; Chris@102: #define BOOST_DETAIL_GCD_HELPER_VAL(Value) (self_type:: Value ) Chris@102: #endif Chris@102: Chris@102: typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1), Chris@102: BOOST_DETAIL_GCD_HELPER_VAL(new_value2) > next_step_type; Chris@102: Chris@102: #undef BOOST_DETAIL_GCD_HELPER_VAL Chris@102: Chris@102: public: Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, value = next_step_type::value ); Chris@102: }; Chris@102: Chris@102: // Non-recursive case Chris@102: template < static_gcd_type Value1 > Chris@102: struct static_gcd_helper_t< Value1, 0UL > Chris@102: { Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 ); Chris@102: }; Chris@102: Chris@102: // Build the LCM from the GCD Chris@102: template < static_gcd_type Value1, static_gcd_type Value2 > Chris@102: struct static_lcm_helper_t Chris@102: { Chris@102: typedef static_gcd_helper_t gcd_type; Chris@102: Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 / gcd_type::value Chris@102: * Value2 ); Chris@102: }; Chris@102: Chris@102: // Special case for zero-GCD values Chris@102: template < > Chris@102: struct static_lcm_helper_t< 0UL, 0UL > Chris@102: { Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, value = 0UL ); Chris@102: }; Chris@102: Chris@102: } // namespace detail Chris@102: Chris@102: Chris@102: // Compile-time greatest common divisor evaluator class declaration --------// Chris@102: Chris@102: template < static_gcd_type Value1, static_gcd_type Value2 > struct static_gcd Chris@102: { Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_gcd_helper_t::value) ); Chris@102: }; // boost::integer::static_gcd Chris@102: Chris@102: #if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) Chris@102: template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_gcd< Value1, Value2 >::value; Chris@102: #endif Chris@102: Chris@102: // Compile-time least common multiple evaluator class declaration ----------// Chris@102: Chris@102: template < static_gcd_type Value1, static_gcd_type Value2 > struct static_lcm Chris@102: { Chris@102: BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_lcm_helper_t::value) ); Chris@102: }; // boost::integer::static_lcm Chris@102: Chris@102: #if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) Chris@102: template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_lcm< Value1, Value2 >::value; Chris@102: #endif Chris@102: Chris@102: } // namespace integer Chris@102: } // namespace boost Chris@102: Chris@102: Chris@102: #endif // BOOST_INTEGER_COMMON_FACTOR_CT_HPP