Topic: constexpr overloading


Author: David Stone <deusexsophismata@gmail.com>
Date: Tue, 8 Oct 2013 19:25:08 -0700 (PDT)
Raw View
------=_Part_1015_28220192.1381285508470
Content-Type: text/plain; charset=ISO-8859-1

I would like the ability to write different functions depending on whether
the argument to a function is a compile-time constant or not. What I want
is similar to what is outlined here:

http://stackoverflow.com/questions/15232758/detecting-constexpr-with-sfinae

However, the solution there only works for determining whether a particular
function was declared as constexpr. It cannot be used to determine whether
a function argument is a known value at compile time. Similarly, the
is_constexpr function outlined here:
http://stackoverflow.com/questions/13299394/is-is-constexpr-possible-in-c11
cannot be used with enable_if and a trailing return type because function
arguments are never considered constexpr, even if they are compile-time
constants known to the compiler in a constexpr function. That is to say,
the following code will not work:

namespace {

template<typename T>
constexpr typename std::remove_reference<T>::type makeprval(T && t) {
    return t;
}

#define is_constexpr(e) noexcept(makeprval(e))

template<typename T>
constexpr auto f(T && t) -> typename std::enable_if<is_constexpr(t), bool>::type
{
    return true;
}
template<typename T>
constexpr auto f(T && t) -> typename std::enable_if<!is_constexpr(t), bool
>::type {
    return false;
}

}    // namespace

int main() {
    static_assert(f(0), "Should be constexpr");
    int a = 0;
    static_assert(!f(a), "Should not be constexpr");
}



Even though the value passed to t in the first case is a compile-time
constant expression, it is not usable in a context that requires a constant
expression.

I have several use cases for this (and several other people do as well,
judging by the number of StackOverflow questions asking if this is
possible). The one that is motivating this proposal is a class that
represents an integer with compile-time bounds (`ranged_integer`). A
ranged_integer in general should only be explicitly constructible from a
built-in integer type. However, if it can be statically determined that the
value falls within the range of this ranged_integer, then I would like to
allow an implicit constructor. Right now, I can only do this if the range
of the type of the built-in integer type falls entirely within the range of
the ranged_integer. This dramatically reduces the usefulness, as most
ranged_integer types will have a range smaller than that of int, but
integer literals are by default typed as int.

The practical effect of this is that declaring a constexpr array of
ranged_integer is much more cumbersome than it should be. I would like to
be able to just declare something like

static constexpr ranged_integer<0, 40> array[] = {
    5, 7, 2, 8, 3, 0, 36
};



And get compile-time checks that all of the values are in the range.
Instead, the best I can do (and require my users to do!) is something like

using type = ranged_integer<0, 40>;
static constexpr type array[] = {
    type(5), type(7), type(2), type(8), type(3), type(0), type(36)
};



My class also provides automatic flexing of ranges in arithmetic
operations. For instance, ranged_integer<0, 1> * ranged_integer<1, 2> gives
a type of ranged_integer<0, 2>. When doing arithmetic with constant values,
my users have to either accept an unnecessarily wide range (all the type
system can tell me is that this number you are multiplying by is equivalent
to ranged_integer<INT_MIN, INT_MAX>) or else have them again call the
constructor or use a factory function. Currently I have used the factory
function approach in my own code, so ranged_integer<0, 2>(1) *
make_ranged<5>() gives a type of ranged_integer<0, 10> with a value of 5.

If it were possible to declare a function parameter as constexpr, then we
could overload on it and all of these problems would go away. The other
solution would be to have a library function is_constexpr that works for
function parameters and can be used with enable_if. However, this would be
tricky when you account for compiler optimizations that lead to parameters
being known compile-time constants in a release build due to inlining, but
not in debug builds.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1015_28220192.1381285508470
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I would like the ability to write different functions depe=
nding on whether the argument to a function is a compile-time constant or n=
ot. What I want is similar to what is outlined here:<br><br>http://stackove=
rflow.com/questions/15232758/detecting-constexpr-with-sfinae<br><br>However=
, the solution there only works for determining whether a particular functi=
on was declared as constexpr. It cannot be used to determine whether a func=
tion argument is a known value at compile time. Similarly, the is_constexpr=
 function outlined here: http://stackoverflow.com/questions/13299394/is-is-=
constexpr-possible-in-c11 cannot be used with enable_if and a trailing retu=
rn type because function arguments are never considered constexpr, even if =
they are compile-time constants known to the compiler in a constexpr functi=
on. That is to say, the following code will not work:<br><br><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: r=
gb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break=
-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">namespace</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">template</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">co=
nstexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">remove_reference</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">type makeprval</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">T </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&amp;&amp;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> t</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> t</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">#define</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> is_constexpr</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">e</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> noexcept</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">make=
prval</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">e</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">))</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;<br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">T </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> t</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">e=
nable_if</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">is_const=
expr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">t</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">bool</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">type </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">true</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">template</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">T </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> t</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">enable=
_if</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;!</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">is_constexpr=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">t</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">bool</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">type </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>false</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">// namespace</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;<br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> main</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">static_assert</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">f</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #080;" class=3D"styled-by-prettify">"Should be constexpr"</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> a </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">static_assert</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(!</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">f</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">a</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #080;" class=3D"styled-by-prettify">"Should not be constexpr"</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span></div></code></div><br><br>=
Even though the value passed to t in the first case is a compile-time const=
ant expression, it is not usable in a context that requires a constant expr=
ession.<br><br>I have several use cases for this (and several other people =
do as well, judging by the number of StackOverflow questions asking if this=
 is possible). The one that is motivating this proposal is a class that rep=
resents an integer with compile-time bounds (`ranged_integer`). A ranged_in=
teger in general should only be explicitly constructible from a built-in in=
teger type. However, if it can be statically determined that the value fall=
s within the range of this ranged_integer, then I would like to allow an im=
plicit constructor. Right now, I can only do this if the range of the type =
of the built-in integer type falls entirely within the range of the ranged_=
integer. This dramatically reduces the usefulness, as most ranged_integer t=
ypes will have a range smaller than that of int, but integer literals are b=
y default typed as int.<br><br>The practical effect of this is that declari=
ng a constexpr array of ranged_integer is much more cumbersome than it shou=
ld be. I would like to be able to just declare something like<br><br><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
span style=3D"color: #008;" class=3D"styled-by-prettify">static</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> ranged_integer</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">40</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> array</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[]<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">5</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by=
-prettify">7</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">2</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">8</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">3</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">36</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span></div></code></div><br><br>And get compile-time check=
s that all of the values are in the range. Instead, the best I can do (and =
require my users to do!) is something like<br><br><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">using</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> type </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> ranged_integer</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">40<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">static</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> type array</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">[]</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; &nbsp; type</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify=
">5</span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> type</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">7</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">),</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> type</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">2</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
type</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #066;" class=3D"styled-by-prettify">8</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> type</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">3</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">),</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> type</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> type</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">36</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span></div></code></div><br><br>My class also provides automatic=
 flexing of ranges in arithmetic operations. For instance, ranged_integer&l=
t;0, 1&gt; * ranged_integer&lt;1, 2&gt; gives a type of ranged_integer&lt;0=
, 2&gt;. When doing arithmetic with constant values, my users have to eithe=
r accept an unnecessarily wide range (all the type system can tell me is th=
at this number you are multiplying by is equivalent to ranged_integer&lt;IN=
T_MIN, INT_MAX&gt;) or else have them again call the constructor or use a f=
actory function. Currently I have used the factory function approach in my =
own code, so ranged_integer&lt;0, 2&gt;(1) * make_ranged&lt;5&gt;() gives a=
 type of ranged_integer&lt;0, 10&gt; with a value of 5.<br><br>If it were p=
ossible to declare a function parameter as constexpr, then we could overloa=
d on it and all of these problems would go away. The other solution would b=
e to have a library function is_constexpr that works for function parameter=
s and can be used with enable_if. However, this would be tricky when you ac=
count for compiler optimizations that lead to parameters being known compil=
e-time constants in a release build due to inlining, but not in debug build=
s.<style type=3D"text/css">p, li { white-space: pre-wrap; }
</style></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1015_28220192.1381285508470--

.


Author: MJanes <max.jns@gmail.com>
Date: Wed, 9 Oct 2013 00:11:46 -0700 (PDT)
Raw View
------=_Part_1119_18174730.1381302707032
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

as an alternative solution, you could implement a user defined literal, say=
=20
"_ri", and forbid implicit construction from integers altogether, so as to=
=20
write:

static constexpr ranged_integer<0, 40> array[] =3D { 5_ri, 7_ri, // ...

ranged_integer<0, 2>(1) * 5_ri

Il giorno mercoled=EC 9 ottobre 2013 04:25:08 UTC+2, David Stone ha scritto=
:
>
> I would like the ability to write different functions depending on whethe=
r=20
> the argument to a function is a compile-time constant or not. What I want=
=20
> is similar to what is outlined here:
>
> http://stackoverflow.com/questions/15232758/detecting-constexpr-with-sfin=
ae
>
> However, the solution there only works for determining whether a=20
> particular function was declared as constexpr. It cannot be used to=20
> determine whether a function argument is a known value at compile time.=
=20
> Similarly, the is_constexpr function outlined here:=20
> http://stackoverflow.com/questions/13299394/is-is-constexpr-possible-in-c=
11cannot be used with enable_if and a trailing return type because function=
=20
> arguments are never considered constexpr, even if they are compile-time=
=20
> constants known to the compiler in a constexpr function. That is to say,=
=20
> the following code will not work:
>
> namespace {
>
> template<typename T>
> constexpr typename std::remove_reference<T>::type makeprval(T && t) {
>     return t;
> }
>
> #define is_constexpr(e) noexcept(makeprval(e))
> =20
> template<typename T>
> constexpr auto f(T && t) -> typename std::enable_if<is_constexpr(t), bool
> >::type {
>     return true;
> }
> template<typename T>
> constexpr auto f(T && t) -> typename std::enable_if<!is_constexpr(t), boo=
l
> >::type {
>     return false;
> }
>
> }    // namespace
> =20
> int main() {
>     static_assert(f(0), "Should be constexpr");
>     int a =3D 0;
>     static_assert(!f(a), "Should not be constexpr");
> }
>
>
>
> Even though the value passed to t in the first case is a compile-time=20
> constant expression, it is not usable in a context that requires a consta=
nt=20
> expression.
>
> I have several use cases for this (and several other people do as well,=
=20
> judging by the number of StackOverflow questions asking if this is=20
> possible). The one that is motivating this proposal is a class that=20
> represents an integer with compile-time bounds (`ranged_integer`). A=20
> ranged_integer in general should only be explicitly constructible from a=
=20
> built-in integer type. However, if it can be statically determined that t=
he=20
> value falls within the range of this ranged_integer, then I would like to=
=20
> allow an implicit constructor. Right now, I can only do this if the range=
=20
> of the type of the built-in integer type falls entirely within the range =
of=20
> the ranged_integer. This dramatically reduces the usefulness, as most=20
> ranged_integer types will have a range smaller than that of int, but=20
> integer literals are by default typed as int.
>
> The practical effect of this is that declaring a constexpr array of=20
> ranged_integer is much more cumbersome than it should be. I would like to=
=20
> be able to just declare something like
>
> static constexpr ranged_integer<0, 40> array[] =3D {
>     5, 7, 2, 8, 3, 0, 36
> };
>
>
>
> And get compile-time checks that all of the values are in the range.=20
> Instead, the best I can do (and require my users to do!) is something lik=
e
>
> using type =3D ranged_integer<0, 40>;
> static constexpr type array[] =3D {
>     type(5), type(7), type(2), type(8), type(3), type(0), type(36)
> };
>
>
>
> My class also provides automatic flexing of ranges in arithmetic=20
> operations. For instance, ranged_integer<0, 1> * ranged_integer<1, 2> giv=
es=20
> a type of ranged_integer<0, 2>. When doing arithmetic with constant value=
s,=20
> my users have to either accept an unnecessarily wide range (all the type=
=20
> system can tell me is that this number you are multiplying by is equivale=
nt=20
> to ranged_integer<INT_MIN, INT_MAX>) or else have them again call the=20
> constructor or use a factory function. Currently I have used the factory=
=20
> function approach in my own code, so ranged_integer<0, 2>(1) *=20
> make_ranged<5>() gives a type of ranged_integer<0, 10> with a value of 5.
>
> If it were possible to declare a function parameter as constexpr, then we=
=20
> could overload on it and all of these problems would go away. The other=
=20
> solution would be to have a library function is_constexpr that works for=
=20
> function parameters and can be used with enable_if. However, this would b=
e=20
> tricky when you account for compiler optimizations that lead to parameter=
s=20
> being known compile-time constants in a release build due to inlining, bu=
t=20
> not in debug builds.
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_1119_18174730.1381302707032
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">as an alternative solution, you could implement a user def=
ined literal, say "_ri", and forbid implicit construction from integers alt=
ogether, so as to write:<br><br>static constexpr ranged_integer&lt;0, 40&gt=
; array[] =3D { 5_ri, 7_ri, // ...<br><br>ranged_integer&lt;0, 2&gt;(1) * 5=
_ri<br><br>Il giorno mercoled=EC 9 ottobre 2013 04:25:08 UTC+2, David Stone=
 ha scritto:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I=
 would like the ability to write different functions depending on whether t=
he argument to a function is a compile-time constant or not. What I want is=
 similar to what is outlined here:<br><br><a href=3D"http://stackoverflow.c=
om/questions/15232758/detecting-constexpr-with-sfinae" target=3D"_blank">ht=
tp://stackoverflow.com/<wbr>questions/15232758/detecting-<wbr>constexpr-wit=
h-sfinae</a><br><br>However, the solution there only works for determining =
whether a particular function was declared as constexpr. It cannot be used =
to determine whether a function argument is a known value at compile time. =
Similarly, the is_constexpr function outlined here: <a href=3D"http://stack=
overflow.com/questions/13299394/is-is-constexpr-possible-in-c11" target=3D"=
_blank">http://stackoverflow.com/<wbr>questions/13299394/is-is-<wbr>constex=
pr-possible-in-c11</a> cannot be used with enable_if and a trailing return =
type because function arguments are never considered constexpr, even if the=
y are compile-time constants known to the compiler in a constexpr function.=
 That is to say, the following code will not work:<br><br><div style=3D"bac=
kground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:s=
olid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color=
:#008">namespace</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">{</span><span style=3D"color:#000"><br><br></span><span style=3D"=
color:#008">template</span><span style=3D"color:#660">&lt;</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> T</span><span s=
tyle=3D"color:#660">&gt;</span><span style=3D"color:#000"><br></span><span =
style=3D"color:#008">constexpr</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">typename</span><span style=3D"color:#000"> std</spa=
n><span style=3D"color:#660">::</span><span style=3D"color:#000">remove_ref=
erence</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#00=
0">T</span><span style=3D"color:#660">&gt;::</span><span style=3D"color:#00=
0">type makeprval</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">T </span><span style=3D"color:#660">&amp;&amp;</span><span style=
=3D"color:#000"> t</span><span style=3D"color:#660">)</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color=
:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#008">return</span><sp=
an style=3D"color:#000"> t</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br><br></span><span style=3D"color:#800">#define</span><=
span style=3D"color:#000"> is_constexpr</span><span style=3D"color:#660">(<=
/span><span style=3D"color:#000">e</span><span style=3D"color:#660">)</span=
><span style=3D"color:#000"> noexcept</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">makeprval</span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">e</span><span style=3D"color:#660">))</sp=
an><span style=3D"color:#000"><br>&nbsp;<br></span><span style=3D"color:#00=
8">template</span><span style=3D"color:#660">&lt;</span><span style=3D"colo=
r:#008">typename</span><span style=3D"color:#000"> T</span><span style=3D"c=
olor:#660">&gt;</span><span style=3D"color:#000"><br></span><span style=3D"=
color:#008">constexpr</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> f</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">T </span><span style=3D"=
color:#660">&amp;&amp;</span><span style=3D"color:#000"> t</span><span styl=
e=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">-&gt;</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">typename</span><span style=3D"color:#000"> std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">enable_if</span><span s=
tyle=3D"color:#660">&lt;</span><span style=3D"color:#000">is_constexpr</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">t</span><sp=
an style=3D"color:#660">)<wbr>,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">bool</span><span style=3D"color:#660">&gt;::</span=
><span style=3D"color:#000">type </span><span style=3D"color:#660">{</span>=
<span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#0=
08">return</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">true</span><span style=3D"color:#660">;</span><span style=3D"color:#000=
"><br></span><span style=3D"color:#660">}</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#008">template</span><span style=3D"color:#=
660">&lt;</span><span style=3D"color:#008">typename</span><span style=3D"co=
lor:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#008">constexpr</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> f</span><span style=3D"color:#660">(</span><span style=3D"=
color:#000">T </span><span style=3D"color:#660">&amp;&amp;</span><span styl=
e=3D"color:#000"> t</span><span style=3D"color:#660">)</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">-&gt;</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">typename</span><span style=
=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">enable_if</span><span style=3D"color:#660">&lt;!</span><spa=
n style=3D"color:#000">is_constexpr</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">t</span><span style=3D"color:#660"><wbr>),</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">bool</span=
><span style=3D"color:#660">&gt;::</span><span style=3D"color:#000">type </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbs=
p; &nbsp; </span><span style=3D"color:#008">return</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">false</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"color:=
#660">}</span><span style=3D"color:#000"><br><br></span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"> &nbsp; &nbsp;</span><span style=
=3D"color:#800">// namespace</span><span style=3D"color:#000"><br>&nbsp;<br=
></span><span style=3D"color:#008">int</span><span style=3D"color:#000"> ma=
in</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbs=
p; &nbsp; </span><span style=3D"color:#008">static_assert</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">f</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#066">0</span><span style=3D"color:=
#660">),</span><span style=3D"color:#000"> </span><span style=3D"color:#080=
">"Should be constexpr"</span><span style=3D"color:#660">);</span><span sty=
le=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#008">int</=
span><span style=3D"color:#000"> a </span><span style=3D"color:#660">=3D</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#066">0</span><=
span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nb=
sp; </span><span style=3D"color:#008">static_assert</span><span style=3D"co=
lor:#660">(!</span><span style=3D"color:#000">f</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">a</span><span style=3D"color:#660"=
>),</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"Sh=
ould not be constexpr"</span><span style=3D"color:#660">);</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br><br></span></div></code></div><br><br>Even though the v=
alue passed to t in the first case is a compile-time constant expression, i=
t is not usable in a context that requires a constant expression.<br><br>I =
have several use cases for this (and several other people do as well, judgi=
ng by the number of StackOverflow questions asking if this is possible). Th=
e one that is motivating this proposal is a class that represents an intege=
r with compile-time bounds (`ranged_integer`). A ranged_integer in general =
should only be explicitly constructible from a built-in integer type. Howev=
er, if it can be statically determined that the value falls within the rang=
e of this ranged_integer, then I would like to allow an implicit constructo=
r. Right now, I can only do this if the range of the type of the built-in i=
nteger type falls entirely within the range of the ranged_integer. This dra=
matically reduces the usefulness, as most ranged_integer types will have a =
range smaller than that of int, but integer literals are by default typed a=
s int.<br><br>The practical effect of this is that declaring a constexpr ar=
ray of ranged_integer is much more cumbersome than it should be. I would li=
ke to be able to just declare something like<br><br><div style=3D"backgroun=
d-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;b=
order-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#008"=
>static</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>constexpr</span><span style=3D"color:#000"> ranged_integer</span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#066">0</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">40</span><span style=3D"color:#660">&gt;</span><span style=3D"co=
lor:#000"> array</span><span style=3D"color:#660">[]</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#00=
0"><br>&nbsp; &nbsp; </span><span style=3D"color:#066">5</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">7</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">2</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">8</s=
pan><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><=
span style=3D"color:#066">3</span><span style=3D"color:#660">,</span><span =
style=3D"color:#000"> </span><span style=3D"color:#066">0</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">36</span><span style=3D"color:#000"><br></span><span style=3D"co=
lor:#660">};</span><span style=3D"color:#000"><br><br></span></div></code><=
/div><br><br>And get compile-time checks that all of the values are in the =
range. Instead, the best I can do (and require my users to do!) is somethin=
g like<br><br><div style=3D"background-color:rgb(250,250,250);border-color:=
rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word">=
<code><div><span style=3D"color:#008">using</span><span style=3D"color:#000=
"> type </span><span style=3D"color:#660">=3D</span><span style=3D"color:#0=
00"> ranged_integer</span><span style=3D"color:#660">&lt;</span><span style=
=3D"color:#066">0</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#066">40</span><span style=3D"color=
:#660">&gt;;</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#008">static</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#008">constexpr</span><span style=3D"color:#000"> type array</span><span=
 style=3D"color:#660">[]</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; type</=
span><span style=3D"color:#660">(</span><span style=3D"color:#066">5</span>=
<span style=3D"color:#660">),</span><span style=3D"color:#000"> type</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#066">7</span><span=
 style=3D"color:#660">),</span><span style=3D"color:#000"> type</span><span=
 style=3D"color:#660">(</span><span style=3D"color:#066">2</span><span styl=
e=3D"color:#660">),</span><span style=3D"color:#000"> type</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#066">8</span><span style=3D"=
color:#660">),</span><span style=3D"color:#000"> type</span><span style=3D"=
color:#660">(</span><span style=3D"color:#066">3</span><span style=3D"color=
:#660">),</span><span style=3D"color:#000"> type</span><span style=3D"color=
:#660">(</span><span style=3D"color:#066">0</span><span style=3D"color:#660=
">),</span><span style=3D"color:#000"> type</span><span style=3D"color:#660=
">(</span><span style=3D"color:#066">36</span><span style=3D"color:#660">)<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</=
span><span style=3D"color:#000"><br></span><span style=3D"color:#000"><br><=
/span></div></code></div><br><br>My class also provides automatic flexing o=
f ranges in arithmetic operations. For instance, ranged_integer&lt;0, 1&gt;=
 * ranged_integer&lt;1, 2&gt; gives a type of ranged_integer&lt;0, 2&gt;. W=
hen doing arithmetic with constant values, my users have to either accept a=
n unnecessarily wide range (all the type system can tell me is that this nu=
mber you are multiplying by is equivalent to ranged_integer&lt;INT_MIN, INT=
_MAX&gt;) or else have them again call the constructor or use a factory fun=
ction. Currently I have used the factory function approach in my own code, =
so ranged_integer&lt;0, 2&gt;(1) * make_ranged&lt;5&gt;() gives a type of r=
anged_integer&lt;0, 10&gt; with a value of 5.<br><br>If it were possible to=
 declare a function parameter as constexpr, then we could overload on it an=
d all of these problems would go away. The other solution would be to have =
a library function is_constexpr that works for function parameters and can =
be used with enable_if. However, this would be tricky when you account for =
compiler optimizations that lead to parameters being known compile-time con=
stants in a release build due to inlining, but not in debug builds.</div></=
blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1119_18174730.1381302707032--

.


Author: MJanes <max.jns@gmail.com>
Date: Wed, 9 Oct 2013 00:12:23 -0700 (PDT)
Raw View
------=_Part_1080_3081214.1381302744072
Content-Type: text/plain; charset=ISO-8859-1

as an alternative solution, you could implement a user defined literal, say
"_ri", and forbid implicit construction from integers altogether, so as to
write:

static constexpr ranged_integer<0, 40> array[] = { 5_ri, 7_ri, // ...

ranged_integer<0, 2>(1) * 5_ri

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1080_3081214.1381302744072
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">as an alternative solution, you could implement a user def=
ined literal, say "_ri", and forbid implicit construction from integers alt=
ogether, so as to write:<br><br>static constexpr ranged_integer&lt;0, 40&gt=
; array[] =3D { 5_ri, 7_ri, // ...<br><br>ranged_integer&lt;0, 2&gt;(1) * 5=
_ri<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1080_3081214.1381302744072--

.


Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Thu, 10 Oct 2013 00:40:22 -0700 (PDT)
Raw View
------=_Part_3097_19230316.1381390822139
Content-Type: text/plain; charset=ISO-8859-1

Wouldn't that mean that the constant 40 is built into _ri? Not very useful
if so...

Den onsdagen den 9:e oktober 2013 kl. 09:12:23 UTC+2 skrev MJanes:
>
> as an alternative solution, you could implement a user defined literal,
> say "_ri", and forbid implicit construction from integers altogether, so as
> to write:
>
> static constexpr ranged_integer<0, 40> array[] = { 5_ri, 7_ri, // ...
>
> ranged_integer<0, 2>(1) * 5_ri
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_3097_19230316.1381390822139
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Wouldn't that mean that the constant 40 is built into _ri?=
 Not very useful if so...<br><br>Den onsdagen den 9:e oktober 2013 kl. 09:1=
2:23 UTC+2 skrev MJanes:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr">as an alternative solution, you could implement a user defined l=
iteral, say "_ri", and forbid implicit construction from integers altogethe=
r, so as to write:<br><br>static constexpr ranged_integer&lt;0, 40&gt; arra=
y[] =3D { 5_ri, 7_ri, // ...<br><br>ranged_integer&lt;0, 2&gt;(1) * 5_ri<br=
></div></blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3097_19230316.1381390822139--

.


Author: MJanes <max.jns@gmail.com>
Date: Thu, 10 Oct 2013 01:01:15 -0700 (PDT)
Raw View
------=_Part_1886_7950355.1381392075033
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Il giorno gioved=EC 10 ottobre 2013 09:40:22 UTC+2, Bengt Gustafsson ha=20
scritto:
>
> Wouldn't that mean that the constant 40 is built into _ri? Not very usefu=
l=20
> if so...
>

I think not; to my understanding, you can writing something like=20

template <int N> struct the_literal {};

template <int Min, int Max >
struct the_class
{
    template<int N> the_class( the_literal<N> i )
    {
        static_assert( N>=3DMin && N<=3DMax, "oops" );
    }   =20
};

the_class<0,40> arr[] =3D { the_literal<14>{}, the_literal<31>{} };

where 5_ri would have type the_literal<5> ...

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_1886_7950355.1381392075033
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Il giorno gioved=EC 10 ottobre 2013 09:40:22 UTC+2, Bengt =
Gustafsson ha scritto:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">Wouldn't that mean that the constant 40 is built into _ri? Not ver=
y useful if so...<br></div></blockquote><div><br>I think not; to my underst=
anding, you can writing something like <br><br><div class=3D"prettyprint" s=
tyle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 1=
87); border-style: solid; border-width: 1px; word-wrap: break-word;"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> N</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> the_literal </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">Min</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">Max</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> the_class<br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> N</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> t=
he_class</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> the_litera=
l</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">N</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> i </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">static_assert</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> N</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;=3D</span><span style=3D"color: =
#606;" class=3D"styled-by-prettify">Min</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> N</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&lt;=3D</span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">Max</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #080;" class=3D"styled-by-prettify">"oops"</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;<br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br>the_class</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">,</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">40</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> arr</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">[]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> the_literal</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">14</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&gt;{},</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> the_literal</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&lt;</span><span style=3D"color: #066;" class=3D"=
styled-by-prettify">31</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&gt;{}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n></div></code></div><br>where 5_ri would have type the_literal&lt;5&gt; ..=
..<br><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1886_7950355.1381392075033--

.


Author: David Krauss <potswa@gmail.com>
Date: Fri, 11 Oct 2013 14:55:36 +0800
Raw View
On 10/10/13 3:40 PM, Bengt Gustafsson wrote:
> Wouldn't that mean that the constant 40 is built into _ri? Not very useful
> if so...

I think you have a chance if you use a literal operator template to
build the values 5, 7, etc into the return type of _ri, then either the
value 40 is received by the conversion function of _ri return or the
ranged_integer provides the converting constructor from a ranged literal.

It might be better to provide a literal template returning some flavor
of std::integral_constant and not tie that part to ranged_integer.

In any case, then you end up shadowing all the runtime operations with
separate meta-evaluation. I *guess* that's what you asked for in the
first place... good luck!

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: David Stone <deusexsophismata@gmail.com>
Date: Fri, 11 Oct 2013 08:45:18 -0700 (PDT)
Raw View
------=_Part_204_22276178.1381506318053
Content-Type: text/plain; charset=ISO-8859-1

My original design did include a _ranged_integer literal. However, I soon
realized that the implementation was far more complex than a make_ranged<n>
function template and was actually less flexible. The function template
accepts all compile-time constants, not just literal values.

My goal here isn't to do something that cannot be done, but to do something
that cannot be done without extra work from users. Right now, if a user of
my library tries to make an array, they have to explicitly construct from
each literal. I have a program that makes heavy use of arrays of constants
(thousands of them), and it is much more succinct and readable without the
extra constructor calls, but I get lots of compile-time checks with them.
That's a trade-off I would rather not have to make.

A possibly more important example is the naive use of math in my library.
If the user tries to add a ranged_integer and a literal (or otherwise
constexpr usable value), the bounds of their result have to assume the
worst case of an "int" being anywhere in the range [INT_MIN, INT_MAX], even
though we know at compile time where it actually is. Without the ability to
overload on constexpr, I don't believe I can solve this problem, which
makes this type of library much harder to use.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_204_22276178.1381506318053
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">My original design did include a _ranged_integer literal. =
However, I soon realized that the implementation was far more complex than =
a make_ranged&lt;n&gt; function template and was actually less flexible. Th=
e function template accepts all compile-time constants, not just literal va=
lues.<br><br>My goal here isn't to do something that cannot be done, but to=
 do something that cannot be done without extra work from users. Right now,=
 if a user of my library tries to make an array, they have to explicitly co=
nstruct from each literal. I have a program that makes heavy use of arrays =
of constants (thousands of them), and it is much more succinct and readable=
 without the extra constructor calls, but I get lots of compile-time checks=
 with them. That's a trade-off I would rather not have to make.<br><br>A po=
ssibly more important example is the naive use of math in my library. If th=
e user tries to add a ranged_integer and a literal (or otherwise constexpr =
usable value), the bounds of their result have to assume the worst case of =
an "int" being anywhere in the range [INT_MIN, INT_MAX], even though we kno=
w at compile time where it actually is. Without the ability to overload on =
constexpr, I don't believe I can solve this problem, which makes this type =
of library much harder to use.<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_204_22276178.1381506318053--

.


Author: MJanes <max.jns@gmail.com>
Date: Fri, 11 Oct 2013 10:02:39 -0700 (PDT)
Raw View
------=_Part_372_16811065.1381510959888
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Il giorno venerd=EC 11 ottobre 2013 17:45:18 UTC+2, David Stone ha scritto:
>
> My original design did include a _ranged_integer literal. However, I soon=
=20
> realized that the implementation was far more complex than a make_ranged<=
n>=20
> function template and was actually less flexible. The function template=
=20
> accepts all compile-time constants, not just literal values.
>

you can provide both=20

A possibly more important example is the naive use of math in my library.=
=20
> If the user tries to add a ranged_integer and a literal (or otherwise=20
> constexpr usable value), the bounds of their result have to assume the=20
> worst case of an "int" being anywhere in the range [INT_MIN, INT_MAX], ev=
en=20
> though we know at compile time where it actually is.=20
>

I don't understand why. Please, consider the following code:

// the class

template< int Min, int Max =3D Min >
struct ranged_integer { int v; };

template< int N >
struct ranged_integer<N,N> {};

template< int N1, int M1, int N > // or whatever your own "flexing" logic i=
s
ranged_integer<N1,M1+N> operator+( ranged_integer<N1,M1> r, ranged_integer<=
N
> )
    { return {r.v+N}; }

// the literal

template< int e >
struct pow10: std::integral_constant<int, 10 * pow10<e-1>::value > {};

template<>
struct pow10<0>: std::integral_constant<int, 1 > {};

template< int... >
struct make_literal {};

template< int i >
struct make_literal<i>: std::integral_constant<int,i - '0'> {};

template< int first, int... other >
struct make_literal< first, other... >: std::integral_constant<int,
    ( first - '0'  )* pow10<sizeof...(other)>::value + make_literal<other
....>::value > {};

template<char... c>
constexpr ranged_integer< make_literal<c...>::value > operator"" _ri () {=
=20
return {}; }

given the above ( roughly tested ) code, "ranged_integer<1,2>{1} + 223_ri"=
=20
gives a "ranged_integer<1,225>{224}", this is what you expected, isn't it ?

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_372_16811065.1381510959888
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Il giorno venerd=EC 11 ottobre 2013 17:45:18 UTC+2, David =
Stone ha scritto:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div>My origi=
nal design did include a _ranged_integer literal. However, I soon realized =
that the implementation was far more complex than a make_ranged&lt;n&gt; fu=
nction template and was actually less flexible. The function template accep=
ts all compile-time constants, not just literal values.<br></div></blockquo=
te><div dir=3D"ltr"><br>you can provide both <br><br><blockquote style=3D"m=
argin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); paddin=
g-left: 1ex;" class=3D"gmail_quote">A possibly more important example is th=
e naive use of math in my library. If the user tries to add a ranged_intege=
r and a literal (or otherwise constexpr usable value), the bounds of their =
result have to assume the worst case of an "int" being anywhere in the rang=
e [INT_MIN, INT_MAX], even though we know at compile time where it actually=
 is. <br></blockquote><div><br>I don't understand why. Please, consider the=
 following code:<br><br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-b=
y-prettify">// the class</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">template</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">Min</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Max</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">Min</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> ranged_integer </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> v</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> N </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> ranged_integer</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>N</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">N</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> N1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> M1</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> N </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// or=
 whatever your own "flexing" logic is</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>ranged_integer</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">N1</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">M1</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">+</span><span style=3D"color: #000;" class=3D"styled-by-prettify">N</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">+(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> ranged_integer</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">N1</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">M1</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ranged_in=
teger</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">N</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">r=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">v</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">N</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>// the literal</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">template</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> e </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> pow10</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">integral_constant</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">10</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> pow10</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">e</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">-</span><span style=3D"color: #066;" class=3D"styled-by-prettify"=
>1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">value </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{};</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&lt;&gt;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> pow10</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #066;" class=3D"styled-by=
-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&gt;:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">integral_constant=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">1</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">template=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> make_literal </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{};</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">template</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> i </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> make_literal</span><span style=3D"color:=
 #080;" class=3D"styled-by-prettify">&lt;i&gt;</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">integral_constant</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">i =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">'0'</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">template</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">i=
nt</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> first</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> other </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> make_literal</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> first</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> o=
ther</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&gt;:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">integral_constant</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> first </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">-</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">'0'=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp;</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)*</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> pow10</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">sizeof</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">...(</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">other</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">)&gt;::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">value </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">+</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> make_literal</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">other</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">...&gt;::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">value </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> c</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> ranged_integer</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> make_literal</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">c</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
....&gt;::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">v=
alue </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span=
 style=3D"color: #080;" class=3D"styled-by-prettify">""</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> _ri </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></code><=
/div><br>given the above ( roughly tested ) code, "ranged_integer&lt;1,2&gt=
;{1} + 223_ri" gives a "ranged_integer&lt;1,225&gt;{224}", this is what you=
 expected, isn't it ?<br> <br></div></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_372_16811065.1381510959888--

.


Author: David Stone <deusexsophismata@gmail.com>
Date: Fri, 11 Oct 2013 10:19:06 -0700 (PDT)
Raw View
------=_Part_399_14325274.1381511946696
Content-Type: text/plain; charset=ISO-8859-1

The literal version provides no value over a non-type function template. It
accepts literals but also anything declared constexpr or anything that is a
template argument. The only difference is the syntax of `ri<5>()` vs
`5_ri`. I can (and already do!) provide math that gives the correct bounds
with the sum of two ranged_integer, and all the literal would do is return
a ranged_integer (it cannot give me anything extra). My point is that if a
user users a regular literal, I cannot provide the same tight bounds that I
can if they used my make_ranged function (or a literal version, as I said,
they are identical). If I had the ability to overload on constexpr, then I
could use its value as a template parameter and provide the type that I am
after.

In short, my goal is to burden the user at little as possible and let them
mostly do arithmetic as they are used to. If it is harder to use my library
than it is to use built-in integers, then many people won't bother.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_399_14325274.1381511946696
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The literal version provides no value over a non-type func=
tion template. It accepts literals but also anything declared constexpr or =
anything that is a template argument. The only difference is the syntax of =
`ri&lt;5&gt;()` vs `5_ri`. I can (and already do!) provide math that gives =
the correct bounds with the sum of two ranged_integer, and all the literal =
would do is return a ranged_integer (it cannot give me anything extra). My =
point is that if a user users a regular literal, I cannot provide the same =
tight bounds that I can if they used my make_ranged function (or a literal =
version, as I said, they are identical). If I had the ability to overload o=
n constexpr, then I could use its value as a template parameter and provide=
 the type that I am after.<br><br>In short, my goal is to burden the user a=
t little as possible and let them mostly do arithmetic as they are used to.=
 If it is harder to use my library than it is to use built-in integers, the=
n many people won't bother.<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_399_14325274.1381511946696--

.


Author: MJanes <max.jns@gmail.com>
Date: Sat, 12 Oct 2013 01:11:38 -0700 (PDT)
Raw View
------=_Part_1013_13928017.1381565499014
Content-Type: text/plain; charset=ISO-8859-1

ok, I got it now, your goal specifically is to let users use built-in
integers with your library, provided they are known at compile time. That
is, you want an implicit converting constructor from int to
ranged_integer<N,M> enabled iff the int is constexpr. Maybe, a compromise
solution could be the ability of static_assert'ing that an evaluation is
effectively compile-time or not, so having your implicit conversion to give
at least an error in the latter case.

Regarding the literal vs make template issue, I disagree on them being
identical. I bet that if you ask anybody what a "5_ri" is, most will tell
you at least that it's some flavor of "5", even without ever looking at
your code. Conversely, the expression "ri<5>()" could mean anything and
you'll end up using a much more descriptive name anyway ( as you're doing
now, ie make_ranged ) contracdicting your statement that the literal and
the template are just syntactical variants, they're not and one should
provide both of them ( the literal as a replacement of builtin integers and
the template as a way to <explicitly> express the intention of making a
rangedinteger ).

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1013_13928017.1381565499014
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">ok, I got it now, your goal specifically is to let users u=
se built-in integers with your library, provided they are known at compile =
time. That is, you want an implicit converting constructor from int to rang=
ed_integer&lt;N,M&gt; enabled iff the int is constexpr. Maybe, a compromise=
 solution could be the ability of static_assert'ing that an evaluation is e=
ffectively compile-time or not, so having your implicit conversion to give =
at least an error in the latter case.<br><br>Regarding the literal vs make =
template issue, I disagree on them being identical. I bet that if you ask a=
nybody what a "5_ri" is, most will tell you at least that it's some flavor =
of "5", even without ever looking at your code. Conversely, the expression =
"ri&lt;5&gt;()" could mean anything and you'll end up using a much more des=
criptive name anyway ( as you're doing now, ie make_ranged ) contracdicting=
 your statement that the literal and the template are just syntactical vari=
ants, they're not and one should provide both of them ( the literal as a re=
placement of builtin integers and the template as a way to &lt;explicitly&g=
t; express the intention of making a rangedinteger ).<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1013_13928017.1381565499014--

.


Author: MJanes <max.jns@gmail.com>
Date: Sat, 12 Oct 2013 06:16:41 -0700 (PDT)
Raw View
------=_Part_181_23499567.1381583801779
Content-Type: text/plain; charset=ISO-8859-1

BTW, it seems there's already an open proposal on this, take a look at the
paper: "N3583 Exploring constexpr at Runtime",
http://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3583.pdf

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_181_23499567.1381583801779
Content-Type: text/html; charset=ISO-8859-1

<div dir="ltr">BTW, it seems there's already an open proposal on this, take a look at the paper: "N3583 Exploring constexpr at Runtime", http://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3583.pdf</div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_181_23499567.1381583801779--

.