Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-01-31 09:59:02


Hi, I'm having the following problem (?) with mpl::integral_c.

Since it is intended to encapsulate an "Integral Constant",
I thought that it somewhat superseded BOOST_STATIC_CONSTANT.
IOWs, I figured that if I have something of the form:

struct X
{
  BOOST_STATIC_CONSTANT( Type, ID = Val ) ;
} ;

it could be rewritten as:

struct X
{
  mpl::integral_c<Type,Val> ID ;
} ;

The benefit is that X::ID becomes a lot more usable on those compilers with
poor
non-type template parameter support.

Specifically, I designed the traits class of the Numeric Conversion Library
to expose mpl::integral_c and mpl::bool_c in place of BOOST_STATIC_CONSTANT
for its different value fields.

So, first of all, do you agree that the mpl form is better?

Unfortunately, while I was just about to release the library for formal
review,
I tested it with gcc3.2 and stumped into the following:

The conversion traits class exposes integral constant expressions of
_enumeration_ type;
however, according to my attempts, mpl::integral_c<> cannot be used with
enumeration types
on gcc3.2 as the following short test shows:

#include<iostream>
#include "boost/mpl/integral_c.hpp"

enum LETTERS { a,b,c } ;

int main()
{
  typedef boost::mpl::integral_c<LETTERS,a> A ;
  LETTERS v = A::value ;
}

/cygdrive/c/boost/boost/boost/mpl/integral_c.hpp: In instantiation of
`boost::mpl::integral_c<LETTERS, a>':
/cygdrive/c/boost/boost/libs/numeric/conversion/test/short_test1.cpp:60:
instantiated from here
/cygdrive/c/boost/boost/boost/mpl/integral_c.hpp:56: invalid conversion from
`
   int' to `LETTERS'
/cygdrive/c/boost/boost/boost/mpl/integral_c.hpp: In instantiation of
`boost::mpl::integral_c<LETTERS, a>':
/cygdrive/c/boost/boost/libs/numeric/conversion/test/short_test1.cpp:60:
instantiated from here
/cygdrive/c/boost/boost/boost/mpl/integral_c.hpp:57: invalid conversion from
`
   int' to `LETTERS'

The errors show that the problem is related to the definition of next,prior:

    typedef integral_c<T, (value + 1)> next;
    typedef integral_c<T, (value - 1)> prior;

Solution:

There are two possibilities AFAICT:

(a) since there is int_c<> already, remove next/prior from integral_c
altoghether.
(b) add a special enum_c<>.

What do you think?

--
Fernando Cacciola

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