8,603 questions
1
vote
1
answer
130
views
Unexpected overload resolution on clang [duplicate]
(I was making an integer class to replace C's stuff, then this hit me. I wanted an overload for pointer arithmetic.)
MSVC and GCC pass without errors or warnings.
Compilation:
g++ -std=c++2c -fsyntax-...
19
votes
2
answers
807
views
How can a longer C++ implicit conversion chain succeed and a strict subchain of it fail in operator lookup?
Background
Our original problem was that including boost::logic::tribool caused an expression of the form referenceToClass != nullptr to compile happily. We ultimately tracked this down to the ...
5
votes
2
answers
157
views
Is this assignment to brace-enclosed string constant really illegal in C++?
I am porting a large codebase from Linux/g++ to MacOS/Clang. I hit this compiler error in multiple places in Clang (where g++ builds successfully and does the right thing at run time):
error: ...
3
votes
1
answer
165
views
Any usages of default operator!=, operator< ...?
Let simplify to operator== and operator!=.
If I have ..operator==..=default; then I do not need to have the operator!= to be defaulted.
struct S {
bool operator==(const S&) const = default;
// ...
0
votes
0
answers
104
views
Why does std::equality_comparable_with not work in the simplest case? [duplicate]
#include <concepts>
struct A {};
struct B {};
constexpr bool operator==(A, A) {
return true;
}
constexpr bool operator==(B, B) {
return true;
}
constexpr bool operator==(A, B) {
...
-1
votes
1
answer
72
views
Prevent duplicate boilerplate operator overloads [duplicate]
This is a follow up of this question, which might have been a XY problem. Anyhow, that was closed within a few minutes, before I could get any real help.
In our large code base (measurement processing ...
1
vote
2
answers
244
views
Prevent duplicate operator overloads implementations
In our large code base (measurement processing application) we've had bugs where values were mixed up because everything is a double. So we decided to try-out strongly named types for things like ...
1
vote
1
answer
42
views
Can I replace an operator in a Julia function when wrapped for testing?
I'm writing a Julia package for testing the behaviour of floating point addition.
module TestModule
const base_add = Base.:+
# used for storing information when addition is done
mutable struct ...
2
votes
1
answer
196
views
What's the reason for std::reference_wrapper to not overload operator->?
A std::reference_wrapper is guaranteed to be initialized (but can be rebound, unlike a normal reference).
Being a wrapper class, what's the reason for std::reference_wrapper not to overload operator-&...
2
votes
3
answers
185
views
Multiple namespaces overloaded operator<<, how can I use them?
I'm reading a book. Obviously there are some failures in it.
In the code below, how can I access plant::operator<< in run() and plant::debug::operator<< in diagnostic()? The compiler can't ...
1
vote
0
answers
49
views
Why does the compiler fail to find the correct function? [duplicate]
I have this generic function:
pub fn bounding_circle<V>(
points: &dyn Fn(usize) -> V,
point_count: usize,
)
where
V: InnerSpace<f32> + Debug + Copy,
for<'x> &...
0
votes
1
answer
109
views
error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'const cs10b_fraction::Fraction')
I get this error even though I overloaded the << operator.
My prototype is as follows, placed within the Fraction class header file.
friend std::ostream& operator << (std::ostream&,...
1
vote
1
answer
123
views
operator<< overload for std::errc is not detected in a std::formatter specialization for custom class in C++
I have a template class and a custom std::formatter specialization for that class to be able to format and print it. When I create this class with std::errc data and try to print it, the compiler ...
0
votes
0
answers
43
views
Explanation of a variadic parameter while overloading << operator for std::tuple [duplicate]
I was going through an example of how to overload operator<< for std::tuple in this cpp reference link.
Here is the example code:
template<typename... Ts>
std::ostream& operator<<...
3
votes
1
answer
118
views
How to implement a case-sensitive `Equals` for operators as `-ceq`
An Equals method on a specific class might be used to implement a PowerShell operator as -eq:
class TestClass {
hidden [String] $_Value
TestClass([String]$Value) { $this._Value = $Value }
[...