Title
range_formatter's set_separator, set_brackets, and underlying functions should be noexcept
Status
ready
Section
[format.range.formatter][format.range.fmtdef][format.tuple]
Submitter
Hewill Kang

Created on 2022-12-11.00:00:00 last changed 3 weeks ago

Messages

Date: 2023-01-06.14:41:04

Proposed resolution:

This wording is relative to N4917.

  1. Modify [format.range.formatter] as indicated:

    namespace std {
      template<class T, class charT = char>
        requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
      class range_formatter {
        formatter<T, charT> underlying_;                                          // exposition only
        basic_string_view<charT> separator_ = STATICALLY-WIDEN<charT>(", ");      // exposition only
        basic_string_view<charT> opening-bracket_ = STATICALLY-WIDEN<charT>("["); // exposition only
        basic_string_view<charT> closing-bracket_ = STATICALLY-WIDEN<charT>("]"); // exposition only
    
      public:
        constexpr void set_separator(basic_string_view<charT> sep) noexcept;
        constexpr void set_brackets(basic_string_view<charT> opening,
                                    basic_string_view<charT> closing) noexcept;
        constexpr formatter<T, charT>& underlying() noexcept { return underlying_; }
        constexpr const formatter<T, charT>& underlying() const noexcept { return underlying_; }
    
        […]
      };
    }
    
    […]
    constexpr void set_separator(basic_string_view<charT> sep) noexcept;
    

    -7- Effects: Equivalent to: separator_ = sep;

    constexpr void set_brackets(basic_string_view<charT> opening, basic_string_view<charT> closing) noexcept;
    

    -8- Effects: Equivalent to:

    opening-bracket_ = opening;
    closing-bracket_ = closing;
    

  2. Modify [format.range.fmtdef] as indicated:

    namespace std {
      template<ranges::input_range R, class charT>
      struct range-default-formatter<range_format::sequence, R, charT> {    // exposition only
      private:
        using maybe-const-r = fmt-maybe-const<R, charT>;                    // exposition only
        range_formatter<remove_cvref_t<ranges::range_reference_t<maybe-const-r>>,
                        charT> underlying_;                                 // exposition only
    
      public:
        constexpr void set_separator(basic_string_view<charT> sep) noexcept;
        constexpr void set_brackets(basic_string_view<charT> opening,
                                    basic_string_view<charT> closing) noexcept;
      
        […]
      };
    }
    
    constexpr void set_separator(basic_string_view<charT> sep) noexcept;
    

    -1- Effects: Equivalent to: underlying_.set_separator(sep);.

    constexpr void set_brackets(basic_string_view<charT> opening, basic_string_view<charT> closing) noexcept;
    

    -2- Effects: Equivalent to: underlying_.set_brackets(opening, closing);.

  3. Modify [format.tuple] as indicated:

    namespace std {
      template<class charT, formattable<charT>... Ts>
      struct formatter<pair-or-tuple<Ts...>, charT> {
      private:
        tuple<formatter<remove_cvref_t<Ts>, charT>...> underlying_;               // exposition only
        basic_string_view<charT> separator_ = STATICALLY-WIDEN<charT>(", ");      // exposition only
        basic_string_view<charT> opening-bracket_ = STATICALLY-WIDEN<charT>("("); // exposition only
        basic_string_view<charT> closing-bracket_ = STATICALLY-WIDEN<charT>(")"); // exposition only
    
      public:
        constexpr void set_separator(basic_string_view<charT> sep) noexcept;
        constexpr void set_brackets(basic_string_view<charT> opening,
                                    basic_string_view<charT> closing) noexcept;
    
        […]
      };
    }
    
    […]
    constexpr void set_separator(basic_string_view<charT> sep) noexcept;
    

    -5- Effects: Equivalent to: separator_ = sep;

    constexpr void set_brackets(basic_string_view<charT> opening, basic_string_view<charT> closing) noexcept;
    

    -6- Effects: Equivalent to:

    opening-bracket_ = opening;
    closing-bracket_ = closing;
    

Date: 2023-01-15.00:00:00

[ 2023-01-06; Reflector poll ]

Set status to Tentatively Ready after eight votes in favour during reflector poll.

Date: 2022-12-11.00:00:00

The set_separator and set_brackets of range_formatter only invoke basic_string_view's assignment operator, which is noexcept, we should add noexcept specifications for them.

In addition, its underlying function returns a reference to the underlying formatter, which never throws, they should also be noexcept.

Similar rules apply to range-default-formatter and formatter's tuple specialization.

History
Date User Action Args
2023-01-06 14:41:04adminsetmessages: + msg13175
2023-01-06 14:41:04adminsetstatus: new -> ready
2022-12-11 18:59:35adminsetmessages: + msg13152
2022-12-11 00:00:00admincreate