C++ Boost

ct_gcd_lcm - コンパイル時 GCD および LCM

はじめに

detail/ct_gcd_lcm.hpp は2つのコンパイル時アルゴリズムを提供する。 最大公約数と最小公倍数である。

梗概

namespace details {
namespace pool {

template <unsigned A, unsigned B>
struct ct_gcd
{
  static const unsigned value = ...;
};
template <unsigned A, unsigned B>
struct ct_lcm
{
  static const unsigned value = ...;
};

} // namespace pool
} // namespace details

意味

Symbol Table
SymbolMeaning
A, Bコンパイル時符号なし定整数[5.19/1]
Semantics
ExpressionResult TypeValuePrecondition
ct_gcd<A, B>::valueコンパイル時符号なし定整数AB の最大公約数 A != 0 && B != 0
ct_lcm<A, B>::valueコンパイル時符号なし定整数AB の最小公倍数 A != 0 && B != 0

注意事項

コンパイル時アルゴリズムであるため、事前条件の違反はコンパイル時エラーを招く。

依存性

標準文書からの抜粋

5.19/1: Expressions: Constant Expressions:". . . 整定数式は、リテラル(2.13)、列挙子、const 変数または定数式(8.5)で初期化された整数ないし列挙型の静的データメンバー、整数ないし列挙型の非型テンプレートパラメータ、sizeof 式のみを含むことができる。 浮動小数リテラル(2.13.3)は整数ないし列挙型にキャストされる場合のみ現れることができる。 整数ないし列挙型への型変換のみが使用できる。 特に、sizeof 式を除いて、関数、クラスオブジェクト、ポインタ、参照は使用できず、代入、増分、減分、関数呼び出し、カンマ演算子は使用できない。"

将来の方向性

このヘッダーは Boost compile-time algorithms ライブラリに置き換えられるかもしれない。


Copyright © 2000, 2001 Stephen Cleary (shammah@voyager.net)

This file can be redistributed and/or modified under the terms found in copyright.html

This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.