Boost logo

Boost Users :

Subject: Re: [Boost-users] Compare boost::system::error_category
From: Richard Damon (Richard_at_[hidden])
Date: 2017-03-26 12:16:39


On 3/25/17 7:24 PM, Niall Douglas via Boost-users wrote:
> On 25/03/2017 23:05, Christopher Pisz via Boost-users wrote:
>> What would be so wrong with category being an actual number to
>> compare against?
>>
>> I don't know anyone whom creates classes and operator == using the
>> address of that class. You guys talk about the standard and what
>> not, and admittedly I've never looked inside how they implement
>> things, but I've never had such problems using the STL either.
> C++ 14 standard subsection 19.5.1.1:
>
> "error_category objects are passed by reference, and two such objects
> are equal if they have the same address. This means that applications
> using custom error_category types should create a single object of each
> such type."
>
> Indeed subsection 19.5.1.3 explicitly says that the comparison operator
> returns (this == &rhs). That puts standard library implementators in a bind.
>
> Niall
>
My guess is that the creators of the standard expect that implementers,
and library creators will take the effort to explicitly create their
error objects to allow them to really be unique. I think this means that
in the presence of things like DLLs in windows and the like, a header
only library doesn't work without special help from the linker, as you
really need to move such objects into a special DLL to keep them unique,
or the library loader needs to be given the references to this object
and it picks one of them to satisfy all the references, ignoring the
other definitions.

For the standard library, this isn't as much of an issue, as it already
needs a compiled module, so there is a spot to put them, it just says
that if you might have troubles staticly linking to parts of the
standard library if you are building such a loadable module, all
loadable modules need to refer to the standard library via a loadable
module to keep things unique. The issue becomes for library creators who
want to try to build a 'header only' library.

-- 
Richard Damon

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net