From: Marc on
On 27 mai, 20:35, Nick Hounsome <nick.houns...(a)googlemail.com> wrote:
> On 27 May, 09:35, Marc <marc.gli...(a)gmail.com> wrote:
>
>
>
> > (thank you and Bo Persson for your answers)
>
> > On May 25, 8:55 pm, Nick Hounsome <nick.houns...(a)googlemail.com>
> > wrote:
>
> > > From the latest draft:
>
> > > For all members declared static constexpr in the numeric_limits
> > > template, specializations shall define
> > > these values in such a way that they are usable as constant
> > > expressions.
>
> > I had a small doubt whether this referred only to the standard
> > specializations or also the user-provided ones, but ok.
>
> > Does "member" only refer to variables like digits? Or does it also
> > refer to functions like min(), in which case it implies a user is
> > forbidden from specializing numeric_limits for a non-literal type (or
> > at least any type for which a compile-time constant is meaningless)?
>
> What do you mean by a non-literal type?

I mean a type that doesn't satisfy the definition in 3.9.0.10 of
N3090. For instance a class that doesn't have any constexpr
constructor. I started thinking about this because of a biginteger
class where every constructor calls new (yes, even for 0).

> A user isn't forbidden from specializing - a user MUST specialize ALL
> the members for any type for which is_specialized is true
[...]
> Yes but that's not a problem they can just return any constant value
> if they are not meaningful.

But if a type can't have constants (say all constructors call new),
you can't return one, even a meaningless one. Which means you aren't
allowed to specialize numeric_limits at all for this type.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Nick Hounsome on
On 30 May, 00:39, Marc <marc.gli...(a)gmail.com> wrote:
> On 27 mai, 20:35, Nick Hounsome <nick.houns...(a)googlemail.com> wrote:
>
> > On 27 May, 09:35, Marc <marc.gli...(a)gmail.com> wrote:
>
> > > (thank you and Bo Persson for your answers)
>
> > > On May 25, 8:55 pm, Nick Hounsome <nick.houns...(a)googlemail.com>
> > > wrote:
>
> > > > From the latest draft:
>
> > > > For all members declared static constexpr in the numeric_limits
> > > > template, specializations shall define
> > > > these values in such a way that they are usable as constant
> > > > expressions.
>
> > > I had a small doubt whether this referred only to the standard
> > > specializations or also the user-provided ones, but ok.
>
> > > Does "member" only refer to variables like digits? Or does it also
> > > refer to functions like min(), in which case it implies a user is
> > > forbidden from specializing numeric_limits for a non-literal type (or
> > > at least any type for which a compile-time constant is meaningless)?
>
> > What do you mean by a non-literal type?
>
> I mean a type that doesn't satisfy the definition in 3.9.0.10 of
> N3090. For instance a class that doesn't have any constexpr
> constructor. I started thinking about this because of a biginteger
> class where every constructor calls new (yes, even for 0).

I see your point.

Of course there are ways around this and a big integer is inherently
large and slow so "optimising" 0 (or maybe also 0,1,-1) might well not
be as bad as you think - It could be done with a magic constexpr ctor
something like biginteger(biginteger::MAGIC_ZERO).

> > A user isn't forbidden from specializing - a user MUST specialize ALL
> > the members for any type for which is_specialized is true
> [...]
> > Yes but that's not a problem they can just return any constant value
> > if they are not meaningful.
>
> But if a type can't have constants (say all constructors call new),
> you can't return one, even a meaningless one. Which means you aren't
> allowed to specialize numeric_limits at all for this type.

Is there any possibility of fudging it by returning something else and
providing the overloads to do the right thing?
i.e. something like having min() return a "struct biginteger0 {};"
and provide bigintger(biginteger0) etc.

There are probably some awkward edge cases and it's probably not
strictly legal but I think it could work especialy as it should never
be used because numeric_limits<biginteger>::is_bounded is false which
means that min() is not meaningful according to the std even though
min() is obviously meaningful for biginteger

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]