Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.

1177. Improve "diagnostic required" wording

Section: 30.5[time.duration]Status:C++11Submitter: Howard HinnantOpened: 2009-07-18Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [time.duration].

View all issues withC++11 status.

Discussion:

"diagnostic required" has been used (by me) for code words meaning "useenable_if to constrain templated functions. This needs to beimproved by referring to the function signature as not participating inthe overload set, and moving this wording to aRemarks paragraph.

[2009-10 Santa Cruz:]

Moved to Ready.

[2009-11-19 Pete opens:]

Oh, and speaking of 1177, most of the changes result in rather convoluted prose.Instead of saying

A shall be B, else C

it should be

C if A is not B

That is:

Rep2 shall be implicitly convertible toCR(Rep1, Rep2), elsethis signature shall not participate in overload resolution.

should be

This signature shall not participate in overload resolution ifRep2 isnot implicitly convertible toCR(Rep1, Rep2).

That is clearer, and eliminates the false requirement thatRep2 "shallbe" convertible.

[2009-11-19 Howard adds:]

I've updated the wording to match Pete's suggestion and included bullet 16from1195(i).

[2009-11-19 Jens adds:]

Further wording suggestion using "unless":

This signature shall not participate in overload resolution unlessRep2is implicitly convertible toCR(Rep1, Rep2).

[2009-11-20 Howard adds:]

I've updated the wording to match Jens' suggestion.

[2009-11-22 Moved to Tentatively Ready after 5 positive votes on c++std-lib.]

Proposed resolution:

[This proposed resolution addresses947(i) and974(i). ]

  1. Change 30.5.2[time.duration.cons] (and reorder theRemarksparagraphs per 16.3.2.4[structure.specifications]):

    template <class Rep2>   explicit duration(const Rep2& r);

    Requires:Remarks:This constructor shall notparticipate in overload resolution unlessRep2shall beis implicitly convertible torep and

    • treat_as_floating_point<rep>::valueshall beistrue, or
    • treat_as_floating_point<Rep2>::valueshall beisfalse.

    Diagnostic required [Example:

    duration<int, milli> d(3); // OK duration<int, milli> d(3.5); // error

    end example]

    Effects: Constructs an object of typeduration.

    Postcondition:count() == static_cast<rep>(r).

    template <class Rep2, class Period2>  duration(const duration<Rep2, Period2>& d);

    Requires:Remarks:This constructor shall notparticipate in overload resolution unlesstreat_as_floating_point<rep>::valueshall beistrue orratio_divide<Period2,period>::type::denshall beis 1.Diagnosticrequired. [Note: This requirement prevents implicit truncationerror when converting between integral-based duration types. Such a constructioncould easily lead to confusion about the value of the duration. —endnote] [Example:

    duration<int, milli> ms(3); duration<int, micro> us = ms; // OK duration<int, milli> ms2 = us; // error

    end example]

    Effects: Constructs an object of typeduration, constructingrep_ fromduration_cast<duration>(d).count().

  2. Change the following paragraphs in 30.5.6[time.duration.nonmember]:

    template <class Rep1, class Period, class Rep2>   duration<typename common_type<Rep1, Rep2>::type, Period>   operator*(const duration<Rep1, Period>& d, const Rep2& s);

    RequiresRemarks:This operator shall notparticipate in overload resolution unlessRep2shallbeis implicitly convertible toCR(Rep1, Rep2).Diagnostic required.

    template <class Rep1, class Period, class Rep2>   duration<typename common_type<Rep1, Rep2>::type, Period>   operator*(const Rep1& s, const duration<Rep2, Period>& d);

    RequiresRemarks:This operator shall notparticipate in overload resolution unlessRep1shallbeis implicitly convertible toCR(Rep1, Rep2).Diagnostic required.

    template <class Rep1, class Period, class Rep2>   duration<typename common_type<Rep1, Rep2>::type, Period>   operator/(const duration<Rep1, Period>& d, const Rep2& s);

    RequiresRemarks:This operator shall notparticipate in overload resolution unlessRep2shallbeis implicitly convertible toCR(Rep1, Rep2) andRep2shall not beis not an instantiation ofduration.Diagnostic required.

    template <class Rep1, class Period, class Rep2>   duration<typename common_type<Rep1, Rep2>::type, Period>   operator%(const duration<Rep1, Period>& d, const Rep2& s);

    RequiresRemarks:This operator shall notparticipate in overload resolution unlessRep2shallbeis implicitly convertible toCR(Rep1, Rep2) andRep2shall not beis not an instantiation ofduration.Diagnostic required.

  3. Change the following paragraphs in 30.5.8[time.duration.cast]:

    template <class ToDuration, class Rep, class Period>   ToDuration duration_cast(const duration<Rep, Period>& d);

    RequiresRemarks:This function shall notparticipate in overload resolution unlessToDurationshallbeis an instantiation ofduration.Diagnosticrequired.

  4. Change 30.6.2[time.point.cons]/3 as indicated:

    Requires:Duration2 shall be implicitly convertible toduration.Diagnostic required.

    Remarks: This constructor shall not participate in overloadresolution unlessDuration2 is implicitly convertible toduration.

  5. Change the following paragraphs in 30.6.8[time.point.cast]:

    template <class ToDuration, class Clock, class Duration>   time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);

    RequiresRemarks:This function shall notparticipate in overload resolution unlessToDurationshallbeis an instantiation ofduration.Diagnosticrequired.


[8]ページ先頭

©2009-2026 Movatter.jp