stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <>
Subject RE: tests/utilities/
Date Fri, 20 Jun 2008 18:59:01 GMT

Eric Lemings wrote:
>Just a brief side note.  I was just reviewing this test and 
>noticed that
>pointers are not tested though they are valid scalar types suitable for
>use as integral_constant parameters.  I think references may be valid
>parameters also.

I'm not sure.

The first thing that jumps to mind is that a pointer is not of
'integral' type. An enumeration isn't really an integral type either,
but they are implicitly convertible to one. Pointers aren't convertible
to integral type without a cast.

According to temp.arg.nontype, a non-type, non-template template
parameter must be one of

  -- an integral constant expression
  -- the name of a non-type template-parameter
  -- the address of an object or function with external linkage...
  -- a constant expression that evaluates to a null pointer value
  -- a constant expression that evaluates to a null member pointer value
  -- a pointer to member

So, yes, it is legal to use a pointer as a non-type template parameter.

The issue I have is that the integral_constant<T,V> is supposed to
define an integral constant of type T with value V. Section expr.const
says that a constant expression is an integral constant expression if it
is of integral or enumeration type. An integral constant expression can
be used as an array bound, a case expression, a bit field length,
enumeration initializer, static member initializer and as integral or
enumeration non-type template arguments.

I'm pretty sure you can't use a pointer value as an array bound, case
expression, bit field length or enumeration initializer, so they aren't
really integral constants.

So I am sure you can instantiate std::integral_constant<void
(class_t::*)(), &class::method>, but I'm not sure if it something that
should be tested.


View raw message