Title
Should std::basic_format_context be default-constructible/copyable/movable?
Status
new
Section
[format.context]
Submitter
Jiang An

Created on 2024-03-24.00:00:00 last changed 1 month ago

Messages

Date: 2024-03-26.15:08:20

Proposed resolution:

This wording is relative to N4971.

  1. Modify [format.context] as indicated:

    namespace std {
      template<class Out, class charT>
      class basic_format_context {
        basic_format_args<basic_format_context> args_; // exposition only
        Out out_;                                      // exposition only
    
        basic_format_context(const basic_format_context&) = delete;
        basic_format_context& operator=(const basic_format_context&) = delete;
      public:
        using iterator = Out;
        using char_type = charT;
        template<class T> using formatter_type = formatter<T, charT>;
        
        basic_format_arg<basic_format_context> arg(size_t id) const noexcept;
        std::locale locale();
        
        iterator out();
        void advance_to(iterator it);
      };
    }
    
Date: 2024-03-24.00:00:00

Per [format.context], it seems that std::basic_format_context has a default constructor that is effectively defaulted, which means that it is default constructible if and only if OutIt is default constructible. Currently only libstdc++ makes it conditionally default constructible, while libc++ and MSVC STL (together with fmtlib) make it never default constructible.

It seems that basic_format_context objects are supposed to be created by the implementation in some internal way, and user codes are only supposed to modify existing basic_format_context objects during formatting.

History
Date User Action Args
2024-03-26 15:08:20adminsetmessages: + msg14028
2024-03-24 00:00:00admincreate