Comments (6)
That's an interesting one! I hadn't thought of a non-const member function . . .
I think I'm with you on this one - if you must have one, then the canonical form of a member op==() is 'const'.
Perhaps you could capture the non-const case and issue a more sensible compile time error ?
from catch2.
@colonelsammy I could possibly force a descriptive error message - but it would still be limiting your options - what if you don't control the source?
I think providing a non-const operator ==, or an operator == that takes its argument by non-const ref, are the lesser two of four evils (when you add in providing const and non-const overloads and making them do something different). After all the first two are probably just an oversight. The other two are deliberately malicious!
That's why I'm leaning towards supporting the former two at the expense of the latter two.
from catch2.
About limiting your options, remember that the operator==
can be defined outside the class, so even if you can't modify the class in question, you can always define a non-member const operator==
. It's up to you to decide if it's reasonable to put this burden on the library user though. ;)
(But it does seem like a very rare case, and if it saves you a lot of trouble, it may be worth it)
from catch2.
Thanks for the comments.
I've gone with the const_cast approach for now but I may revisit this in the future.
from catch2.
Reading through the comments, I'm having a hard time tracking exactly what is and isn't supported.
I believe these are the four options - which ones are supported? I'm trying to figure out if my current experience is the expected behavior or not.
MyClass {
public:
bool operator==(MyClass &rhs); /* supported ? */
bool operator==(const MyClass &rhs); /* supported ? */
bool operator==(MyClass &rhs) const; /* supported ? */
bool operator==(const MyClass &rhs) const; /* supported ? */
};
from catch2.
Only the last one is.
from catch2.
Related Issues (20)
- Latest macOS system header causes compilation failures on GCC HOT 4
- Compilation fails with `error: arithmetic on a pointer to an incomplete type` HOT 3
- Combine test filters with filenames HOT 2
- Section filter command line option only works for sections without whitespace in name HOT 1
- Separate headers for "extra" std types
- Catch2 does not appear to work with C++23
- version 3.5.4 does not compile
- JUnit and console reporter discrepency.
- Provide means to obtain current test case name and current section name HOT 2
- GENERATOR doesn't allow use constants HOT 1
- Memory leak when using exit()
- Compile Error While using Catch::Clara::Parser HOT 1
- Allow the Catch2 library to be compiled with address sanitizer enabled
- Fixture's destructor called before retrieving uncaught exception's message
- How does (can) auto-registration work?
- CTest (using catch_discover_tests) treats skipped tests as failed HOT 2
- Exit code of 127 when all tests pass (only on Windows Release build) HOT 1
- std::complex output precision
- How to test a custom math library with Catch2 (while catch2 relies on libm) ? HOT 1
- The json reporter does not print results of benchmarks HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from catch2.