C++ Boost

ct_gcd_lcm - Compile-Time GCD and LCM

Introduction

detail/ct_gcd_lcm.hpp provides two compile-time algorithms: greatest common divisor and least common multiple.

Synopsis

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

Semantics

Symbol Table
SymbolMeaning
A, Bcompile-time unsigned integer constants[5.19/1]
Semantics
ExpressionResult TypeValuePrecondition
ct_gcd<A, B>::valuecompile-time unsigned integer constantThe greatest common divisor of A and BA != 0 && B != 0
ct_lcm<A, B>::valuecompile-time unsigned integer constantThe least common multiple of A and BA != 0 && B != 0

Notes

Since these are compile-time algorithms, violation of the preconditions will result in a compile-time error.

Dependencies

Selected Quotations from the Standard

5.19/1: Expressions: Constant Expressions: ". . . An integral constant expression can involve only literals (2.13), enumerators, const variables or static data members of integral or enumeration types initialized with constant expressions (8.5), non-type template parameters of integral or enumeration types, and sizeof expressions. Floating literals (2.13.3) can appear only if they are cast to integral or enumeration types. Only type conversions to integral or enumeration types can be used. In particular, except in sizeof expressions, functions, class objects, pointers, or references shall not be used, and assignment, increment, decrement, function-call, or comma operators shall not be used."

Future Directions

This header may be replaced by a Boost compile-time algorithms library.


Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)

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.