This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

3839. range_formatter's set_separator, set_brackets, and underlying functions should be noexcept

Section: 22.14.7.2 [format.range.formatter], 22.14.7.3 [format.range.fmtdef], 22.14.9 [format.tuple] Status: WP Submitter: Hewill Kang Opened: 2022-12-11 Last modified: 2023-02-13

Priority: Not Prioritized

View all other issues in [format.range.formatter].

View all issues with WP status.

Discussion:

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.

[2023-01-06; Reflector poll]

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

[2023-02-13 Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4917.

  1. Modify 22.14.7.2 [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 22.14.7.3 [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 22.14.9 [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;