Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-05-10 08:00:41


Is there a boost library that allows you to specify the range that a number
can take, e.g.

   boost::range< int, 1, 12 > month;

generating an error on an invalid range, e.g.

   month = 20; // [1] oops!

Also, is it possible to distinguish between a number literal like the above
and a variable assignment, like:

   month = m; // [2]

The logic behind this is to provide compile-time checks where possible, so
[1] would produce a compile-time error and [2] would be a run-time error.
You could also do something like:

   inline char & string::operator[]( boost::range< int, 5, 10 > i ){ ... }
   // ...
   string s;
   s[ 1 ] = 'a'; // oops!

and

   class date
   {
      boost::range< int, 1, 12 > month;
      public:
         inline date( boost::range< int, 1, 12 > m ): month( m ){}
   };

Regards,
Reece

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk