Thread: Why isn't this a Contradiction? i.e What did I understand wrong?

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    Why isn't this a Contradiction? i.e What did I understand wrong?

    The book "Thinking in C++(V2)" gives something like the following example:
    Code:
    int main() 
    {
        ifstream in("a.cpp");
        while(in.get(*cout.rdbuf()))
            in.ignore();
        return 0;
    }
    It compiles and works correctly.

    But my <streambuf> file says:
    Quote Originally Posted by streambuf
    * -# Stream buffers can impose various constraints on the sequences
    * they control. Some constraints are:
    * - The controlled input sequence can be not readable.
    * - The controlled output sequence can be not writable. <------------- [THIS is the line I'm talking about]
    * - The controlled sequences can be associated with the contents of
    * other representations for character sequences, such as external
    * files.
    * - The controlled sequences can support operations @e directly to or
    * from associated sequences.
    * - The controlled sequences can impose limitations on how the
    * program can read characters from a sequence, write characters to
    * a sequence, put characters back into an input sequence, or alter
    * the stream position.
    * .
    But the code compiles and runs as expected.
    Isn't cout's streambuf being written on in the example ?
    Or..more likely...what punchline am I missing ?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by streambuf
    * -# Stream buffers can impose various constraints on the sequences
    * they control. Some constraints are:
    * - The controlled input sequence can be not readable.
    * - The controlled output sequence can be not writable. <------------- [THIS is the line I'm talking about]
    * - The controlled sequences can be associated with the contents of
    * other representations for character sequences, such as external
    * files.
    * - The controlled sequences can support operations @e directly to or
    * from associated sequences.
    * - The controlled sequences can impose limitations on how the
    * program can read characters from a sequence, write characters to
    * a sequence, put characters back into an input sequence, or alter
    * the stream position.
    * .
    I think the truly operative phrase here is "Stream buffers can impose various constraints on the sequences they control."

    it seems to me that the ones they list are a few of the options available, and that not all of them are present in every instance of a streambuf.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Elkvis nailed it.

    The word "can" means "able to" which, because it is not mandatory, is distinct from the meaning of "shall" which means "has to".

    In some legal contracts, the word "shall" is used to state essential (non-negotiable) requirements, whereas "can" is used to state that something is desirable (nice to have, but negotiable)
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Elkvis
    ....and that not all of them are present in every instance of a streambuf.....
    Quote Originally Posted by grumpy
    .....whereas "can" is used to state that something is desirable (nice to have, but negotiable)....
    Wouldn't that make using streambuf `s(and its children) very non portable ?
    ..if .. say the runtime library stops allowing something which a piece of code relied upon...
    or if the code is compiled with a different compiler ?

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It can affect portability, yes.

    The trick is to understand what can be relied on and what cannot. Using multiple compilers (and running your tests with each) can help with that.

    Bear in mind that the quoted information is not from the standard. It is presumably a view of one library vendor about some qualities that may be acceptable.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 39
    Last Post: 01-18-2009, 11:53 PM
  2. I don't understand what is wrong...
    By flaran in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2006, 06:46 AM
  3. Can't understand what I'm doing wrong.
    By agentxx04 in forum C Programming
    Replies: 11
    Last Post: 10-22-2004, 07:53 PM
  4. help......i dont understand what i am doing wrong?
    By Grifftt in forum C Programming
    Replies: 2
    Last Post: 10-18-2002, 11:37 PM
  5. I don't understand what i'm doing wrong..
    By knutso in forum C Programming
    Replies: 4
    Last Post: 03-15-2002, 07:37 AM