Boost logo

Boost :

From: Daryle Walker (dwalker07_at_[hidden])
Date: 2002-10-25 01:42:39


As another poster on this subject has said, Roman numbers don't have
different math rules, they are just a different external representation
of natural numbers. This suggests that the place for new code is in
the I/O system! We'll use a special locale with custom facets. It
could be like (I have a version of GCC 3):

template<typename _CharT, typename _InIter>
class roman_num_get : public std::num_get
{
public:
     // blah blah...

protected:
     virtual ~roman_num_get();

     virtual iter_type do_get(iter_type, iter_type, ios_base&,
      ios_base::iostate&, unsigned short&) const;

     virtual iter_type do_get(iter_type, iter_type, ios_base&,
      ios_base::iostate&, unsigned int&) const;

     virtual iter_type do_get(iter_type, iter_type, ios_base&,
      ios_base::iostate&, unsigned long&) const;

#ifdef UNSIGNED_LONG_LONG // whatever...
     virtual iter_type do_get(iter_type, iter_type, ios_base&,
      ios_base::iostate&, unsigned long long&) const;
#endif

     //...
};

template<typename _CharT, typename _OutIter>
class roman_num_put : public std::num_put
{
public:
     // blah blah...

protected:
     virtual ~roman_num_put();

     virtual iter_type do_put(iter_type, ios_base&, char_type, unsigned
long)
      const;

#ifdef UNSIGNED_LONG_LONG // whatever...
     virtual iter_type do_put(iter_type, ios_base&, char_type,
      unsigned long long) const;
#endif

     //...
};

(Unlike most of the other facets in the header file, there are no
*_byname variants for these facets. Is that supposed to be the case?)

There is a special case: zero. Maybe you could use whatever (Latin)
word/phrase the Romans used for zero.

Daryle


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