[system] error_code.hpp - questionable includes

Hi, I noticed that system/error_code.hpp caused some unexpected increase in compilation time, and looked trough its includes. The following seems not needed: #include <boost/cstdint.hpp> #include <boost/assert.hpp> #include <boost/operators.hpp> #include <boost/noncopyable.hpp> // 1) #include <stdexcept> #include <functional> // 2) 1) noncopyable is used to tell that a class (error_category) with pure virtual functions cannot be copied. This is implicit in the language, so really not needed. Unless there's a compelling reason to make sure derived classes can't be copyable either, but I didn't see any reason for this? I didn't look very close though, could've missed it. 2) inclusion of <functional> seems only needed to have the following: bool operator<( const error_category & rhs ) const { return std::less<const error_category*>()( this, &rhs ); } I can't guess the reason for using std::less instead of simply writing '<', but surely it can be expressed without std::less, no? And before getting the common Booster's answer when asking to remove #includes: Yes, I am aware of precompiled headers. I use them, too. =) Cheers, Christian P.S. Would it be too much to ask for having a separate header for the error_code's ostream operators?

AMDG Christian Holmquist wrote:
I noticed that system/error_code.hpp caused some unexpected increase in compilation time, and looked trough its includes.
The following seems not needed:
#include <boost/cstdint.hpp> #include <boost/assert.hpp> #include <boost/operators.hpp> #include <boost/noncopyable.hpp> // 1) #include <stdexcept> #include <functional> // 2)
1) noncopyable is used to tell that a class (error_category) with pure virtual functions cannot be copied. This is implicit in the language, so really not needed. Unless there's a compelling reason to make sure derived classes can't be copyable either, but I didn't see any reason for this? I didn't look very close though, could've missed it.
boost/noncopyable.hpp is only 37 lines of code and has no dependencies. I highly doubt that removing it will have any effect on compile times.
2) inclusion of <functional> seems only needed to have the following: bool operator<( const error_category & rhs ) const { return std::less<const error_category*>()( this, &rhs ); } I can't guess the reason for using std::less instead of simply writing '<', but surely it can be expressed without std::less, no?
No it can't. operator< is not guaranteed to behave sanely for arbitrary pointers. std::less defines a total ordering for pointers. In Christ, Steven Watanabe

boost/noncopyable.hpp is only 37 lines
of code and has no dependencies. I highly doubt that removing it will have any effect on compile times.
Sure. This can be said about of lot of files, especially in Boost with such a high granularity. With my battling-compilation-time-hat on (which is unfortunately always on nowadays) I choose to remove #includes if at all possible, even when the gain is presumably small.
2)
inclusion of <functional> seems only needed to have the following: bool operator<( const error_category & rhs ) const { return std::less<const error_category*>()( this, &rhs ); } I can't guess the reason for using std::less instead of simply writing '<', but surely it can be expressed without std::less, no?
No it can't. operator< is not guaranteed to behave sanely for arbitrary pointers. std::less defines a total ordering for pointers.
Boost should of course aim for correctness so I stand corrected, but is this a theoretical problem or a real one? Are there platforms where: this < &rhs will be wrong in this case? In Christ,
Steven Watanabe
Thanks, Christian
participants (2)
-
Christian Holmquist
-
Steven Watanabe