
Peter Dimov <pdimov@mmltd.net> wrote:
Christopher Kohlhoff wrote:
Yes, this does makes me think that it might be better if an error_code only had one true value, and that value is represented by whatever category and error number it is created with. It would only compare as equal to another error_code that was created with exactly the same category and error number. Conversion between errors in different categories should then be explicit (using to_errno or to_sysno, say).
It does have the disadvantage that you would be able to have
e1.sysno == e2.sysno && e1.errno == e2.errno && e1 != e2
though. :-)
I think this is a good argument for naming the accessor functions (whether they are member functions or not) to clearly indicate that they perform lossy conversions. To me, the names sysno_value() and errno_value() don't convey this -- they sound like they are simple accessors for data members (until one consults the documentation). And as Peter demonstrates above, one might reasonably expect that comparing all exposed data members would give the same result as operator==. But, if the names were something like to_sysno/to_errno or as_sysno/as_errno, the above expression would become: e1.to_sysno() == e2.to_sysno() && e1.to_errno() == e2.to_errno() && e1 != e2 and I no longer think it looks surprising. Cheers, Chris