lagsht_numbers.h 1.72 KB
Newer Older
1 2 3
#ifndef LAGSHTNUMBERS_SEEN
#define LAGSHTNUMBERS_SEEN

4 5
// Template magic to select the proper data types. These templates
// should not be used outside this file.
6

7 8
namespace LagSHT {

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
template <typename T, bool equalSize> struct sizeChooserHelper__
  { typedef void TYPE; };

template <typename T> struct sizeChooserHelper__<T,true>
  { typedef T TYPE; };

template <typename T1, typename T2, typename T3> struct sizeChooserHelper2__
  { typedef T1 TYPE; };

template <typename T2, typename T3> struct sizeChooserHelper2__ <void, T2, T3>
  { typedef T2 TYPE; };

template <typename T3> struct sizeChooserHelper2__ <void, void, T3>
  { typedef T3 TYPE; };

template <> struct sizeChooserHelper2__ <void, void, void>
  { };

template <int sz, typename T1, typename T2=char, typename T3=char>
  struct sizeChooser__
  {
  typedef typename sizeChooserHelper2__
    <typename sizeChooserHelper__<T1,sizeof(T1)==sz>::TYPE,
     typename sizeChooserHelper__<T2,sizeof(T2)==sz>::TYPE,
     typename sizeChooserHelper__<T3,sizeof(T3)==sz>::TYPE >::TYPE TYPE;
  };

typedef signed char int_1; // correct by definition
typedef unsigned char uint_1; // correct by definition
typedef sizeChooser__<2, short, int>::TYPE int_2;
typedef sizeChooser__<2, unsigned short, unsigned int>::TYPE uint_2;
typedef sizeChooser__<4, int, long, short>::TYPE int_4;
typedef sizeChooser__<4, unsigned int, unsigned long, unsigned short>::TYPE uint_4;
typedef sizeChooser__<8, long, long long>::TYPE int_8;
typedef sizeChooser__<8, unsigned long, unsigned long long>::TYPE uint_8;

typedef sizeChooser__<4, float, double>::TYPE r_4;
typedef sizeChooser__<8, double, long double>::TYPE r_8;
typedef sizeChooser__<16, double, long double>::TYPE r_16;
48

49 50
}//namespace

51
#endif //LAGSHTNUMBERS_SEEN