/* greatest_common_divisor.hpp header file * * Copyright Cromwell D. Enage 2004. Use, modification, and distribution are * subject to 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) */ #ifndef GREATEST_COMMON_DIVISOR_HPP #define GREATEST_COMMON_DIVISOR_HPP /* * Defines the workaround macros for ill-conforming compilers. */ #include /* * Defines the boost::mpl::and_ class template. */ #include /* * Defines the boost::mpl::equal_to class template. */ #include /* * Defines the boost::mpl::if_c class template. */ #include /* * Defines the boost::mpl::integral_c class template. */ #include /* * Defines the boost::mpl::less struct template. */ #include /* * Defines the boost::mpl::modulus_c struct template. */ #include /* * Defines the boost::mpl::negate struct template. */ #include /* * Defines the boost::mpl::not_equal_to struct template. */ #include namespace boost { namespace mpl { /* * Workaround for compilers that don't support partial specialization. */ namespace aux { template struct gcd_impl { template struct result_type { template struct abs_cond { typedef typename less, integral_c >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; template struct abs_N { typedef typename if_c::value, negate >, integral_c >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; template struct less_A_B { typedef typename less, integral_c >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; template struct next_A { typedef typename if_c::value, integral_c, integral_c >::type type; BOOST_STATIC_CONSTANT(IntegralType, value = type::value); }; template struct next_B { typedef typename if_c::value, modulus_c, modulus_c >::type modulus_type; typedef typename modulus_type::type type; BOOST_STATIC_CONSTANT(IntegralType, value = type::value); }; template struct next_bool { typedef typename not_equal_to< integral_c::value>, integral_c >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; template class result_ { private: typedef typename gcd_impl::value> ::template result_type result_type; public: typedef typename result_type ::template result_::value, next_B::value>::type type; }; }; }; template <> struct gcd_impl { template struct result_type { template struct zero_cond { typedef typename equal_to, integral_c >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; template struct abs_cond { typedef typename less, integral_c >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; template struct abs_N { typedef typename if_c::value, negate >, integral_c >::type type; }; template class result_ { private: typedef typename if_c::value, abs_N,abs_N >::type abs_type; public: typedef typename abs_type::type type; }; }; }; template struct gcd_cond { typedef typename and_, integral_c >, not_equal_to, integral_c > >::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; } // namespace aux template class greatest_common_divisor_c { private: typedef typename aux::gcd_impl::value> ::template result_type result_type; public: /* * Metafunction return type. */ typedef typename result_type::template result_::type type; }; } // namespace mpl } // namespace boost #endif /* GREATEST_COMMON_DIVISOR_HPP */