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

2226. wstring_convert methods do not take allocator instance

Section: D.27.2 [depr.conversions.string] Status: NAD Submitter: Glen Fernandes Opened: 2012-12-14 Last modified: 2019-02-26

Priority: Not Prioritized

View other active issues in [depr.conversions.string].

View all other issues in [depr.conversions.string].

View all issues with NAD status.

Discussion:

The wstring_convert class template, described in D.27.2 [depr.conversions.string], does not support custom stateful allocators. It only supports custom stateless allocators.

The to_bytes member function returns basic_string<char, char_traits<char>, Byte_alloc> but it does not take an instance of Byte_alloc to pass to the constructor of the basic_string.

Similarly the from_bytes member function returns basic_string<Elem, char_traits<Elem>, Wide_alloc> but it does not take an instance of Wide_alloc to pass to the constructor of the basic_string.

This makes these two member functions and the wstring_convert class template not usable when Wide_alloc or Byte_alloc are stateful allocators.

[2013-01-22, Glen provides wording]

[2013-03-15 Issues Teleconference]

Moved to NAD Future.

This is clearly an extension that the LEWG may want to take a look at, once we have more experience with appropriate use of allocators with the C++11 model.

[LEWG Kona 2017]

Recommend NAD: Does this follow the pattern? Should be discussed as a group. Do we have the experience with the C++11 allocator model to know that this is the addition to make?

Should to_string() also take an allocator? substr()? Any function that returns a string?

This suggests a larger change.

[Kona 2019]

Jonathan points out: The wstring_convert type is deprecated now.

Proposed resolution:

This wording is relative to N3485.

  1. In D.27.2 [depr.conversions.string]/2 and /6 "Class template wstring_convert synopsis" change the overloads of the member function from_bytes() so that all four overloads take an additional parameter which is an instance of Wide_alloc:

    wide_string from_bytes(char byte, const Wide_alloc& alloc = Wide_alloc());
    wide_string from_bytes(const char *ptr, const Wide_alloc& alloc = Wide_alloc());
    wide_string from_bytes(const byte_string& str, const Wide_alloc& alloc = Wide_alloc());
    wide_string from_bytes(const char *first, const char *last, const Wide_alloc& alloc = Wide_alloc());
    
  2. In D.27.2 [depr.conversions.string] /8 specify that this Wide_alloc allocator parameter is used to construct the wide_string object returned from the function:

    -7- Effects: The first member function shall convert the single-element sequence byte to a wide string. The second member function shall convert the null-terminated sequence beginning at ptr to a wide string. The third member function shall convert the sequence stored in str to a wide string. The fourth member function shall convert the sequence defined by the range [first, last) to a wide string.

    -8- In all cases:

  3. In D.27.2 [depr.conversions.string]/2 and /12 "Class template wstring_convert synopsis" change the overloads of the member function to_bytes() so that all four overloads take an additional parameter which is an instance of Byte_alloc:

    byte_string to_bytes(Elem wchar, const Byte_alloc& alloc = Byte_alloc());
    byte_string to_bytes(const Elem *wptr, const Byte_alloc& alloc = Byte_alloc());
    byte_string to_bytes(const wide_string& wstr, const Byte_alloc& alloc = Byte_alloc());
    byte_string to_bytes(const Elem *first, const Elem *last, const Byte_alloc& alloc = Byte_alloc());
    
  4. In D.27.2 [depr.conversions.string] /13 specify that this Byte_alloc allocator parameter is used to construct the byte_string object returned from the function:

    -12- Effects: The first member function shall convert the single-element sequence wchar to a byte string. The second member function shall convert the null-terminated sequence beginning at wptr to a byte string. The third member function shall convert the sequence stored in wstr to a byte string. The fourth member function shall convert the sequence defined by the range [first, last) to a byte string.

    -13- In all cases: