Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-10-06 10:18:38


----- Original Message -----
From: "Howard Hinnant" <hinnant_at_[hidden]>
> Beman quoth:

> >> Let's see. Something like this:
> >>
> >> #include <stdexcept>
> >>
> >> class lock_error : public std::runtime_error
> >> {
> >> public:
> >> lock_error() : std::runtime_error("thread lock error") { }
> >> };
> >>
> >> Is this conforming code? Note the lack of #include <string>,
> >> that std::runtime_error() takes a const string& argument, and
> >> there is no constructor taking a const char*.
> I believe the standard should say more about this issue, but I to not
> have the standard-eze in hand. Several people have proposed rules, and
> I believe that at least an informal consensus may be forming. My
> personal opinion, which has been influenced by similar words already
> spoken by noted experts, is that the standard should say something like:
>
> > If you explicitly use a standard defined name, then you must explicitly
> > include the associated header. Otherwise you do not have to include
> > the header, even if you are implicitly referring to said object.
>
> Of course the above "rule" would have to be encoded in standard-eze so
> that only high priests are capable of interpreting its true meaning. ;-)
>
> Under this rule, Beman's example would be conforming because it only
> implicitly refers to std::string, not explicitly. Thus #include
> <string> is not necessary. If the example were changed to:
>
> lock_error() : std::runtime_error(std::string("thread lock
> error")) { }
>
> then #include <string> becomes necessary.

<shudder!>That would mean that standard headers would always have to include
definitions for all types they use, because user-defined classes can also
have implicit conversions. I don't think you really mean that, do you?

#inlcude <iosfwd>
struct sstream_pimpl
{
    sstream_pimpl();
    ~sstream_pimpl();
    operator std::basic_stringstream<char>&() const;
    std::basic_stringstream<char>* m_data;
};

void g(std::basic_stringstream<char> const&);

void f()
{
    sstream_pimpl x;
    g(x); // legal?
    x << 1; // legal?
}

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk