Listing 3: Error checking


/*
How to generate compile-time
errors if invalid literals are passed
*/

unsigned long NotABinaryDigit() 
  {
  return( 0 ) ;
  }

template< unsigned long N > struct 
  BinDigitOrError
  {
  enum { value = NotABinaryDigit() } ;
  } ;

struct BinDigitOrError< 1 >
  {
  enum { value = 1 } ;
  } ;

struct BinDigitOrError< 0 >
  {
  enum { value = 0 } ;
  } ;
//End of File