# 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

- <boost/static_assert.hpp> (see Boost.Static_Assert), to ensure preconditions are met.
- <boost/type_traits/ice.hpp> (see Coding Guidelines for Integral Constant Expressions), to help with portability.

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

Revised 05 December, 2006

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

Distributed under 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)