Topic: numeric_limits<time_point> specialization?


Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Thu, 17 Jun 2010 09:51:21 CST
Raw View
On Jun 16, 10:33 am, viboes <vicente.bo...@wanadoo.fr> wrote:
> On Jun 15, 2:47 am, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
>
>
>
> <daniel.krueg...@googlemail.c=.om> wrote:
> > On 14 Jun., 23:24, viboes <vicente.bo...@wanadoo.fr> wrote:
>
> > > The time_point and duration template classes from chrono could be
> > > considered as numeric types. Shouldn't the standard provide a
> > > specialization of numeric_limits for them?
>
> > No, because it would violate a very general requirement from
> > 18.3.1 [limits]/4:
>
> > "Non-arithmetic standard types, such as complex<T> (26.4.2),
> > shall not have specializations"
>
> > I'm not sure what the base of this restriction is, but it would be
> > astonishing if we changed that for time_point/duration, but not for
> > complex.
>
> > HTH & Greetings from Bremen,
>
> > Daniel Kr=FCgler
>
> I don't know why, I thought that this class needed to be specialized
> for UDT. For example if I define a bigint class with a fixed number of
> digits, shouldn't I specialize numeric_limits?

I agree that I would specialize numeric_limits for a user-defined
type that mimics an arithmetic type (like big_int).

But I don't think that it is absolutely necessary to specialize
numeric_limits for user-defined specializations of duration
and time_point. In fact, they already provide some public
access to their extreme values (min/max). But if you need
more, you can specialize std::numeric_limits for
std::chrono::duration<some_type, ...> and
std::chrono::time_point<..., std::chrono::duration<some_type, ...>>
as long as some_type is a user-defined type. Since both
templates depend on further types, you may want to perform
partial specialization, e.g.

namespace std {
 template<class Period>
 class numeric_limits<chrono::duration<some_type, Period>> {
   ...
 };

 template<class Period, class Clock>
 class numeric_limits<chrono::time_point<Clock,
chrono::duration<some_type, Period>>> {
   ...
 };
}

Personally, I consider the need for these specialization as
rather limited.

HTH & Greetings from Bremen,

Daniel Kr=FCgler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: viboes <vicente.botet@wanadoo.fr>
Date: Sat, 19 Jun 2010 02:38:08 CST
Raw View
On Jun 17, 5:51 pm, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
<daniel.krueg...@googlemail.c=.om> wrote:
> On Jun 16, 10:33 am, viboes <vicente.bo...@wanadoo.fr> wrote:
>
>
>
> > On Jun 15, 2:47 am, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
>
> > <daniel.krueg...@googlemail.c=.om> wrote:
> > > On 14 Jun., 23:24, viboes <vicente.bo...@wanadoo.fr> wrote:
>
> > > > The time_point and duration template classes from chrono could be
> > > > considered as numeric types. Shouldn't the standard provide a
> > > > specialization of numeric_limits for them?
>
> > > No, because it would violate a very general requirement from
> > > 18.3.1 [limits]/4:
>
> > > "Non-arithmetic standard types, such as complex<T> (26.4.2),
> > > shall not have specializations"
>
> > > I'm not sure what the base of this restriction is, but it would be
> > > astonishing if we changed that for time_point/duration, but not for
> > > complex.
>
> > > HTH & Greetings from Bremen,
>
> > > Daniel Kr=FCgler
>
> > I don't know why, I thought that this class needed to be specialized
> > for UDT. For example if I define a bigint class with a fixed number of
> > digits, shouldn't I specialize numeric_limits?
>
> I agree that I would specialize numeric_limits for a user-defined
> type that mimics an arithmetic type (like big_int).

Just a question: can we specialize numeric_limits for UDTs?

Vicente


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Sat, 19 Jun 2010 17:18:04 CST
Raw View
On 19 Jun., 10:38, viboes <vicente.bo...@wanadoo.fr> wrote:
> On Jun 17, 5:51 pm, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
>
>
>
> <daniel.krueg...@googlemail.c=.om> wrote:
> > On Jun 16, 10:33 am, viboes <vicente.bo...@wanadoo.fr> wrote:
>
> > > On Jun 15, 2:47 am, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
>
> > > <daniel.krueg...@googlemail.c=.om> wrote:
> > > > On 14 Jun., 23:24, viboes <vicente.bo...@wanadoo.fr> wrote:
>
> > > > > The time_point and duration template classes from chrono could be
> > > > > considered as numeric types. Shouldn't the standard provide a
> > > > > specialization of numeric_limits for them?
>
> > > > No, because it would violate a very general requirement from
> > > > 18.3.1 [limits]/4:
>
> > > > "Non-arithmetic standard types, such as complex<T> (26.4.2),
> > > > shall not have specializations"
>
> > > > I'm not sure what the base of this restriction is, but it would be
> > > > astonishing if we changed that for time_point/duration, but not for
> > > > complex.
>
> > > > HTH & Greetings from Bremen,
>
> > > > Daniel Kr=FCgler
>
> > > I don't know why, I thought that this class needed to be specialized
> > > for UDT. For example if I define a bigint class with a fixed number o=
f
> > > digits, shouldn't I specialize numeric_limits?
>
> > I agree that I would specialize numeric_limits for a user-defined
> > type that mimics an arithmetic type (like big_int).
>
> Just a question: can we specialize numeric_limits for UDTs?

Sure, this is a general freedom explicitly guaranteed by the
standard library, see 17.6.3.2.1  [namespace.std]:

"[..] A program may add a template specialization for any standard
library
template to namespace std only if the declaration depends on a user-
defined
type and the specialization meets the standard library requirements
for the
original template and is not explicitly prohibited. (footnote)"

with the footnote saying:

"Any library code that instantiates other library templates must be
prepared to work adequately with any user-supplied specialization
that
meets the minimum requirements of the Standard."

HTH & Greetings from Bremen,

Daniel Kr=FCgler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: viboes <vicente.botet@wanadoo.fr>
Date: Mon, 14 Jun 2010 15:24:06 CST
Raw View
The time_point and duration template classes from chrono could be
considered as numeric types. Shouldn't the standard provide a
specialization of numeric_limits for them?

Vicente

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Mon, 14 Jun 2010 18:47:43 CST
Raw View
On 14 Jun., 23:24, viboes <vicente.bo...@wanadoo.fr> wrote:
> The time_point and duration template classes from chrono could be
> considered as numeric types. Shouldn't the standard provide a
> specialization of numeric_limits for them?

No, because it would violate a very general requirement from
18.3.1 [limits]/4:

"Non-arithmetic standard types, such as complex<T> (26.4.2),
shall not have specializations"

I'm not sure what the base of this restriction is, but it would be
astonishing if we changed that for time_point/duration, but not for
complex.

HTH & Greetings from Bremen,

Daniel Kr=FCgler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: viboes <vicente.botet@wanadoo.fr>
Date: Wed, 16 Jun 2010 02:33:57 CST
Raw View
On Jun 15, 2:47 am, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
<daniel.krueg...@googlemail.c=.om> wrote:
> On 14 Jun., 23:24, viboes <vicente.bo...@wanadoo.fr> wrote:
>
> > The time_point and duration template classes from chrono could be
> > considered as numeric types. Shouldn't the standard provide a
> > specialization of numeric_limits for them?
>
> No, because it would violate a very general requirement from
> 18.3.1 [limits]/4:
>
> "Non-arithmetic standard types, such as complex<T> (26.4.2),
> shall not have specializations"
>
> I'm not sure what the base of this restriction is, but it would be
> astonishing if we changed that for time_point/duration, but not for
> complex.
>
> HTH & Greetings from Bremen,
>
> Daniel Kr=FCgler

I don't know why, I thought that this class needed to be specialized
for UDT. For example if I define a bigint class with a fixed number of
digits, shouldn't I specialize numeric_limits?

Thanks,Vicente



--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]