The effect of `basic_streambuf::setbuf`

后端 未结 2 1557
名媛妹妹
名媛妹妹 2020-12-17 14:46

My problem is as follows: Martin York claims in this, this, and this answers that one can make a stringstream read from some piece of memory by using basi

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 15:10

    OK. Retract.

    After spending the last couple of days going through the documentation and the the proposals that have been made it now seems clear that this may not work (as it is implementation defined).

    As you note in your description above:

    27.5.2.4.2: 1 Effects: Influences stream buffering in a way that is defined separately for each class derived from basic_streambuf in this Clause (27.8.1.4, 27.9.1.5).

    The effect of setbuf() is really defined by its interaction with 27.8.1.4 underflow();

    Returns: If the input sequence has a read position available, returns traits::to_int_type(*gptr()). Otherwise, returns traits::eof(). Any character in the underlying buffer which has been initialized is considered to be part of the input sequence.

    Also for getting more characters from the stream you need to check 27.9.1.5 showmanyc()

    An implementation might well provide an overriding definition for this function signature if it can determine that more characters can be read from the input sequence.

    Which for the stringstream buffer means it will not get anything as the buffer already holds the whole stream.

    So though it is implementation defined how it does it.
    It is still well defined how it does it.

提交回复
热议问题