Why do the basic_stringbuf and basic_filebuf move constructors have behavior defined by the implementation?

From my copy of the C ++ standard [§27.8.2.1p4]:

basic_stringbuf (basic_stringbuf & rhs);

Effects: moving structures from rvalue rhs. It is determined whether the sequence pointers in * this (eback (), gptr (), egptr (), pbase (), pptr (), epptr ()) get the values ​​that they had . Whether they will do it or not, * this is a link to rhs separate buffers (if any) after construction. Openmode, locale and any other rhs state.

A similar sentence is also used for basic_filebuf(basic_filebuf&& rhs); .

Question

I was wondering why this implementation is implemented? Is there a reason you don't want to copy pointers?

+4
source share
1 answer

There are two obvious implementation methods for a buffer in standard stream buffers:

  • You can embed a buffer in an object by creating a large area for the object, but avoiding memory allocation for small lines or files.
  • You can specify a buffer allocated on the heap and deal with a potentially large buffer by allocating memory.

Depending on the choice of implementation where the buffer lives, you will need a new set of pointer values, or you will want to transfer the pointers as they are. None of the strategies are “better,” and I can present options that combine strategies. Thus, instead of making a choice, you can choose. If your question is why the implementation should [forget] document the choice it made: this is clearly outside of me. My personal guess is that it was assumed that the phase “determined by implementation” would provide freedom of choice, and it was ignored that the consequences were that the implementation should declare its choice (since quotes were discussed: 1.3.10 [defns.impl. defined] - strange without a paragraph number).

+2
source

Source: https://habr.com/ru/post/1443345/


All Articles