| Home | Libraries | People | FAQ | More

## Class template wrapping_int

boost::date_time::wrapping_int — A wrapping integer used to support time durations (WARNING: only instantiate with a signed type).

## Synopsis

    // In header: <boost/date_time/wrapping_int.hpp>

    template<typename int_type_, int_type_ wrap_val>
    class wrapping_int {
    public:
      // types
      typedef int_type_ int_type;

      // construct/copy/destruct
      wrapping_int(int_type);

      // public static functions
      static int_type wrap_value() ;

      // public member functions
      int_type as_int() const;
      operator int_type() const;
      template<typename IntT> IntT add(IntT) ;
      template<typename IntT> IntT subtract(IntT) ;

      // private member functions
      template<typename IntT> IntT calculate_wrap(IntT) ;
    };

## Description

In composite date and time types this type is used to wrap at the day boundary. Ex: A wrapping_int<short, 10> will roll over after nine, and roll under below zero. This gives a range of [0,9]

NOTE: it is strongly recommended that wrapping_int2 be used instead of wrapping_int as wrapping_int is to be depricated at some point soon.

Also Note that warnings will occur if instantiated with an unsigned type. Only a signed type should be used!

### `wrapping_int` public construct/copy/destruct

1.     wrapping_int(int_type v);

   Add, return true if wrapped.

### `wrapping_int` public static functions

1.     static int_type wrap_value() ;

### `wrapping_int` public member functions

1.     int_type as_int() const;

   Explicit converion method.

2.     operator int_type() const;

3.     template<typename IntT> IntT add(IntT v) ;

   Add, return number of wraps performed.

   The sign of the returned value will indicate which direction the wraps went. Ex: add a negative number and wrapping under could occur, this would be indicated by a negative return value. If wrapping over took place, a positive value would be returned

4.     template<typename IntT> IntT subtract(IntT v) ;

   Subtract will return '+d' if wrapping under took place ('d' is the number of wraps).

   The sign of the returned value will indicate which direction the wraps went (positive indicates wrap under, negative indicates wrap over). Ex: subtract a negative number and wrapping over could occur, this would be indicated by a negative return value. If wrapping under took place, a positive value would be returned.

### `wrapping_int` private member functions

1.     template<typename IntT> IntT calculate_wrap(IntT wrap) ;