# 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
Symbol | Meaning
--- | ---
A, B | compile-time unsigned integer constants[5.19/1]

Semantics
Expression | Result Type | Value | Precondition
--- | --- | --- | ---
ct_gcd<A, B>::value | compile-time unsigned integer constant | The greatest common divisor of A and B | A != 0 && B != 0
ct_lcm<A, B>::value | compile-time unsigned integer constant | The least common multiple of A and B | A != 0 && B != 0

## Notes

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

## Dependencies

- "detail/postulate.hpp" (see postulate.html), to ensure preconditions are met.

## 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 (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.