Title
wstring_convert methods do not take allocator instance
Status
nad
Section
[depr.conversions.string]
Submitter
Glen Fernandes

Created on 2012-12-14.00:00:00 last changed 62 months ago

Messages

Date: 2019-02-26.17:49:57

Proposed resolution:

This wording is relative to N3485.

  1. In [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 [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:

    • If the cvtstate object was not constructed with an explicit value, it shall be set to its default value (the initial conversion state) before the conversion begins. Otherwise it shall be left unchanged.

    • The number of input elements successfully converted shall be stored in cvtcount.

    • The Wide_alloc allocator parameter is used to construct the wide_string object returned from the function.

  3. In [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 [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:

    • If the cvtstate object was not constructed with an explicit value, it shall be set to its default value (the initial conversion state) before the conversion begins. Otherwise it shall be left unchanged.

    • The number of input elements successfully converted shall be stored in cvtcount.

    • The Byte_alloc allocator parameter is used to construct the byte_string object returned from the function.

Date: 2019-02-26.17:49:57

[ Kona 2019 ]

Jonathan points out: The wstring_convert type is deprecated now.

Date: 2018-06-22.06:38:21

[ 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.

Date: 2013-03-15.00:00:00

[ 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.

Date: 2013-01-15.00:00:00

[ 2013-01-22, Glen provides wording ]

Date: 2017-04-22.20:36:28

The wstring_convert class template, described in [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.

History
Date User Action Args
2019-02-26 17:49:57adminsetmessages: + msg10326
2018-06-22 06:38:21adminsetmessages: + msg9973
2018-06-22 06:38:21adminsetstatus: lewg -> nad
2014-11-24 15:11:58adminsetstatus: nad future -> lewg
2013-03-18 14:33:00adminsetmessages: + msg6435
2013-03-18 13:02:36adminsetstatus: new -> nad future
2013-03-12 21:28:20adminsetmessages: + msg6384
2013-03-12 21:28:20adminsetmessages: + msg6383
2012-12-14 00:00:00admincreate