This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.
Section: 30.4.1 [time.traits.is.fp] Status: C++11 Submitter: Pete Becker Opened: 2009-01-07 Last modified: 2021-06-06
Priority: Not Prioritized
View all issues with C++11 status.
Discussion:
[time.traits.is_fp] says that the type Rep
"is
assumed to be ... a class emulating an integral type." What are the
requirements for such a type?
[ 2009-05-10 Howard adds: ]
IntegralLike
.
[ Batavia (2009-05): ]
As with issue 953(i), we recommend this issue be addressed in the context of providing concepts for the entire
thread
header.We look forward to proposed wording.
Move to Open.
[ 2009-08-01 Howard adds: ]
I have surveyed all clauses of [time.traits.duration_values], 30.4.3 [time.traits.specializations] and 30.5 [time.duration]. I can not find any clause which involves the use of a
duration::rep
type where the requirements on therep
type are not clearly spelled out. These requirements were carefully crafted to allow any arithmetic type, or any user-defined type emulating an arithmetic type.Indeed,
treat_as_floating_point
becomes completely superfluous ifduration::rep
can never be a class type.There will be some
Rep
types which will not meet the requirements of everyduration
operation. This is no different than the fact thatvector<T>
can easily be used for typesT
which are notDefaultConstructible
, even though some members ofvector<T>
requireT
to beDefaultConstructible
. This is why the requirements onRep
are specified for each operation individually.In [time.traits.is_fp] p1:
template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> { };The
duration
template uses thetreat_as_floating_point
trait to help determine if aduration
object can be converted to anotherduration
with a different tick period. Iftreat_as_floating_point<Rep>::value
istrue
, thenRep
is a floating-point type and implicit conversions are allowed amongduration
s. Otherwise, the implicit convertibility depends on the tick periods of theduration
s. IfRep
is a class type which emulates a floating-point type, the author ofRep
can specializetreat_as_floating_point
so thatduration
will treat thisRep
as if it were a floating-point type. OtherwiseRep
is assumed to be an integral type or a class emulating an integral type.The phrases "a class type which emulates a floating-point type" and "a class emulating an integral type" are clarifying phrases which refer to the summation of all the requirements on the
Rep
type specified in detail elsewhere (and should not be repeated here).This specification has been implemented, now multiple times, and the experience has been favorable. The current specification clearly specifies the requirements at each point of use (though I'd be happy to fix any place I may have missed, but none has been pointed out).
I am amenable to improved wording of this paragraph (and any others), but do not have any suggestions for improved wording at this time. I am strongly opposed to changes which would significantly alter the semantics of the specification under 30 [time] without firmly grounded and documented rationale, example implementation, testing, and user experience which relates a positive experience.
I recommend NAD unless someone wants to produce some clarifying wording.
[ 2009-10 Santa Cruz: ]
Stefanus to provide wording to turn this into a note.
[ 2010-02-11 Stefanus provided wording. ]
[ 2010 Rapperswil: ]
Move to Ready.
[ Adopted at 2010-11 Batavia ]
Proposed resolution:
Change [time.traits.is_fp]/1:
1 The
duration
template uses thetreat_as_floating_point
trait to help determine if aduration
object can be converted to anotherduration
with a different tick period. Iftreat_as_floating_point<Rep>::value
istrue
, thenimplicit conversions are allowed amongRep
is a floating-point type andduration
s. Otherwise, the implicit convertibility depends on the tick periods of theduration
s.If[Note: The intention of this trait is to indicate whether a given class behaves like a floating point type, and thus allows division of one value by another with acceptable loss of precision. IfRep
is a class type which emulates a floating-point type, the author ofRep
can specializetreat_as_floating_point
so that duration will treat thisRep
as if it were a floating-point type. OtherwiseRep
is assumed to be an integral type or a class emulating an integral type.treat_as_floating_point<Rep>::value
isfalse
,Rep
will be treated as if it behaved like an integral type for the purpose of these conversions. — end note]