sentry member class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john

    #1

    sentry member class

    I am reading TC++PL3 and in 21.3.8 it describes the class sentry, which
    is member of basic_istream and basic_ostream.

    Q1: Should we always use the sentry class when we define new functions
    and operators for basic_ostream/basic_istream (ostream/istream)?

    Q2: It is mentioned that we can place code "such as throwing exceptions
    caused by state changes" in the sentry's destructor. However in 14.4.7
    it is mentioned:

    "Exiting from a destructor by throwing an exception is also a violation
    of the standard library requirements (E2)".

    I suppose both sentry's constructor and destructor, are to be provided
    by the implementer of the standard library basic_istream and
    basic_ostream classes?
  • James Kanze

    #2
    Re: sentry member class

    On Sep 15, 4:50 pm, john <j...@no.spamwr ote:
    I am reading TC++PL3 and in 21.3.8 it describes the class sentry, which
    is member of basic_istream and basic_ostream.
    Q1: Should we always use the sentry class when we define new functions
    and operators for basic_ostream/basic_istream (ostream/istream)?
    It depends. If all your operator does is call existing <</>>
    operators, it probably isn't necessary; those operators will
    themselves create an instance of the sentry class. But in
    general, yes.
    Q2: It is mentioned that we can place code "such as throwing exceptions
    caused by state changes" in the sentry's destructor.
    I suspect that you've misquoted something here. You can't place
    anything in sentry's destructor, since it is provided by the
    standard library, and you cannot modify it.
    However in 14.4.7
    it is mentioned:
    "Exiting from a destructor by throwing an exception is also a violation
    of the standard library requirements (E2)".
    I suppose both sentry's constructor and destructor, are to be provided
    by the implementer of the standard library basic_istream and
    basic_ostream classes?
    Exactly.

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


    Comment

    Working...