Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Compile-time GCD and LCM determination

Boost , Math Toolkit 2.5.0 , Chapter 11. Integer Utilities (Greatest Common Divisor and Least Common Multiple)

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Заголовок:

typedef unspecified static_gcd_type;
template < static_gcd_type Value1, static_gcd_type Value2 >
struct boost::math::static_gcd : public mpl::integral_c<static_gcd_type, implementation_defined>
{
};
template < static_gcd_type Value1, static_gcd_type Value2 >
struct boost::math::static_lcm : public mpl::integral_c<static_gcd_type, implementation_defined>
{
};

Тип<static_gcd_type>является самым широким неподписанным целым типом, который поддерживается компилятором для использования в интегрально-постоянных выражениях. Обычно это тот же тип, что и<boost::uintmax_t>, но может вернуться к<unsigned long>для некоторых более старых компиляторов.

Шаблоны класса boost::math::static_gcd и boost::math::static_lcm принимают два параметра шаблона на основе значений типаstatic_gcd_typeи наследуют от типа<boost::mpl::integral_c>. Унаследованные от базового класса, они имеют член, который является наибольшим общим фактором или наименьшим общим множеством, соответственно, аргументов шаблона. Ошибка времени компиляции возникает, если наименьшее общее кратное находится за пределами диапазона<static_gcd_type>.

Example

#include <boost/math/common_factor.hpp>
#include <algorithm>
#include <iterator>
#include <iostream>
int main()
{
   using std::cout;
   using std::endl;
   cout << "The GCD and LCM of 6 and 15 are "
   << boost::math::gcd(6, 15) << " and "
   << boost::math::lcm(6, 15) << ", respectively."
   << endl;
   cout << "The GCD and LCM of 8 and 9 are "
   << boost::math::static_gcd<8, 9>::value
   << " and "
   << boost::math::static_lcm<8, 9>::value
   << ", respectively." << endl;
   int  a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3];
   std::transform( a, a + 3, b, c, boost::math::gcd_evaluator<int>() );
   std::copy( c, c + 3, std::ostream_iterator<int>(cout, " ") );
}

PrevUpHomeNext

Статья Compile-time GCD and LCM determination раздела Math Toolkit 2.5.0 Chapter 11. Integer Utilities (Greatest Common Divisor and Least Common Multiple) может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Chapter 11. Integer Utilities (Greatest Common Divisor and Least Common Multiple) ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-19 22:00:10/0.0065560340881348/0