Skip to main content
Filter by
Sorted by
Tagged with
21 votes
1 answer
655 views

C++ allows us to make union class type without any data members. (cppreference even contain an example with it.) Can one request the compiler to provide default implementation of equality comparison ...
Fedor's user avatar
  • 24.7k
3 votes
1 answer
112 views

I'm trying to learn Rust and I managed to find two ways to solve a question (which was to convert from celsius to fahrenheit). fn convert_only_if_needed(celsius_temp : &f64) -> f64 { if !(*...
Adrián Pinado's user avatar
3 votes
1 answer
177 views

Say I have got a plain old data (POD) struct containing multiple numeric fields. I want to overload the comparison operators so that I can compare two instances of my POD. The problem is that I need ...
Giogre's user avatar
  • 1,664
4 votes
1 answer
191 views

Can comparison operators for a class in C++23 have explicit object parameter of a type distinct from the class type? Consider for example struct A { int i; constexpr bool operator==(this int x,...
Fedor's user avatar
  • 24.7k
4 votes
1 answer
154 views

In the following program, struct A has default friend equality comparison operator, which is redeclared again to get the pointer of the function (&operator==): struct A { friend constexpr bool ...
Fedor's user avatar
  • 24.7k
2 votes
1 answer
210 views

This program struct A { int i = 0; constexpr operator int() const { return i; } constexpr operator int&() { return ++i; } }; struct B { A a; bool operator==(const B &) ...
Fedor's user avatar
  • 24.7k
2 votes
1 answer
127 views

In C++23 a class can have explicit object member functions (with the first parameter prefixed by this), including member comparison operators. Which of them a compiler can generate automatically after ...
Fedor's user avatar
  • 24.7k
-5 votes
1 answer
84 views

Why in Python print(bool(7>8)==False==True) results False, logically it should be True? as bool(7>8) is False, therefore False==False==True -> True==True -> True (NOT False) as the ...
Aman Raj Srivastva's user avatar
3 votes
2 answers
102 views

I would like to understand the impact of the comparison function (< or <=) on both lower_bound and upper_bound functions. Consider this program: #include <iostream> #include <vector> ...
ThunderPhoenix's user avatar
0 votes
1 answer
439 views

My program will not compile, and give the error overloaded functions have similar conversions. What does this mean and how do I fix it? struct DynamicInt { bool operator==(const DynamicInt&); }...
X-Maki's user avatar
  • 41
18 votes
1 answer
2k views

Overloading the operator bool() for a custom class T breaks std::vector<T> comparison operators. The following code tried on the first online compiler google suggest me prints v1 > v2: 0 v1 &...
c.bear's user avatar
  • 1,455
0 votes
0 answers
26 views

I would like to know, how to compare two numbers and push the result (true, false or 1, 0) onto the stack. I know about the cmp instruction, but it only sets the flags. I need something that will ...
kamkow1's user avatar
  • 501
1 vote
0 answers
44 views

I stumbled upon a strange behavior of VBScript when comparing numerical values. I expect it's a rounding issue but I can't figure out how I can improve the code to behave as expected. Dim angle angle ...
Hendrik's user avatar
  • 11
0 votes
3 answers
70 views

# Program1: Take two numbers as input from User and print which one is greater or are they equal. num1 = input("Enter the first number: ") num2 = input("Enter the second number: ")...
Swapnil's user avatar
3 votes
2 answers
329 views

Tuples in Swift seem to conform to Comparable inasmuch as I get these results: print ( (3,0) < (2,10000) ) // false print ( (0,0,5) < (0,0,7) ) // true It seems to do a left-right member-by-...
Anton's user avatar
  • 3,399
0 votes
2 answers
194 views

I am wondering if grouping values with || while comparing a single variable value is considered valid in the latest JavaScript or TypeScript and if not, does anyone know a reason for this to not ...
BangsKeyboards's user avatar
1 vote
0 answers
27 views

I was testing out comparison chaining and I noticed that in certain patterns the some of the function calls are not executed. If I plan on using the function calls to do things what would be the best ...
onering20's user avatar
-3 votes
2 answers
106 views

why there is no output for this? #include <stdio.h> int main() { int i; int array[4] = {10, 25, 36, 42}; // int size=sizeof(array) / sizeof(int); for (i = -1; i < sizeof(...
aleena george's user avatar
-1 votes
2 answers
172 views

char* s =(char*) "sss"; int j = -1; printf("%d", j < strlen(s)); It's mainly about the difference between j < 3 and j < strlen(s). In the above code, the printf() ...
Houxiong Yao's user avatar
1 vote
0 answers
34 views

I'm currently still learning, but am working on a small and simple script. I'm attempting to check the user inputs to ensure they match the desired values of the defined variables. The script works ...
cloudnyn3's user avatar
  • 917
-2 votes
1 answer
72 views

So I'm trying to make a rock, paper, scissors game and I'm trying to make it so that if the user (or computer) either gets 3 points OR the user's (or computer's) score is greater by 2 (like a best 2 ...
Asiah Crutchfield's user avatar
2 votes
1 answer
103 views

For some reason, I get different result when comparing the return value from vector::erase inside a if statement or if I store the value first and then compare. But it seems to only happen with g++. ...
mattsson's user avatar
  • 1,174
5 votes
1 answer
177 views

After switching to C++20 I found that some of our tests failed. The output of the following code is different between C++17 and C++20 modes: https://godbolt.org/z/hx4a98T13 class MyString { public: ...
Osyotr's user avatar
  • 1,352
4 votes
2 answers
303 views

Herb Sutter implemented only a subset of chained comparisons in his cppfront, stating in his keynote (https://youtu.be/fJvPBHErF2U?si=RqcR661yBzcQ8r5_&t=850) that a >= b < c is "...
Paul Jurczak's user avatar
  • 8,630
3 votes
1 answer
126 views

Since C++20 the compiler can generate default comparison operators for a class, including as friend non-member function, see (2) in cppreference.com. I came across the code working in MSVC that does ...
Fedor's user avatar
  • 24.7k
0 votes
0 answers
24 views

I have table mysql with column date, time, subject, description and value. I want to know the value at current day is increase or degrade from the value at last 7 day in the same time. Date ...
luckymanh_74yahoocom's user avatar
0 votes
1 answer
45 views

I am writing a function to determine the prime factors of a number and return them in a doubly linked list. The code is as below. (create_list, add_to_tail, and print_DLL perform operations on the DLL ...
YWH's user avatar
  • 25
-2 votes
1 answer
159 views

I am comparing two string using comparison operators(<,>,=). The output of "a" < "b" In this case is 0. #include<iostream> using namespace std; int main() { cout&...
amit_fiend's user avatar
-3 votes
3 answers
766 views

So, I was following a pacman tutorial and the coder uses & not &&. He doesn't explain what it does though. I searched it up and it says that unlike &&, & checks both ...
Smile D's user avatar
  • 33
36 votes
2 answers
6k views

After upgrading to latest Visual Studio 2022 version 17.6, one of our custom views stopped to be recognized as std::ranges::range. It turned out that the problem was in the presence of both operator ==...
Fedor's user avatar
  • 24.7k
0 votes
1 answer
188 views

I've entered my programming class' exam where i've encountered a question in which i was asked to interpret what would the result of the code block written in C would be and the code block is as ...
ahailtotheKing's user avatar
0 votes
1 answer
53 views

I am absolutely lost as to what is happening here. I am simply comparing the values of two numbers and returning the result. When I'm doing it in a custom property, the result is always False, even ...
Arcturus's user avatar
  • 252
4 votes
2 answers
2k views

The typical reason given for using a biased exponent (also known as offset binary) in floating-point numbers is that it makes comparisons easier. By arranging the fields such that the sign bit takes ...
Thanks for flying Vim's user avatar
1 vote
1 answer
191 views

We have this old code in our repo: bool BufferByteCompareFiles(string filePath1, string filePath2) { int bufferCapacity = 0x400000; var firstFile = File.OpenRead(filePath1); ...
notarobot's user avatar
  • 119
2 votes
2 answers
955 views

If I want to compare two vectors in lexicographical order, I can do as follows: int main() { std::vector<int> a{0, 7, 8, 9}; std::vector<int> b{1, 2, 3, 4}; std::cout << ...
Sourav Kannantha B's user avatar
-1 votes
2 answers
316 views

I was not able to find proper documentation about it. Same thing I did in Javascript and I got False for Both Cases. I know that 3>2 should be treated as (3>2) -> True|1, therefore 3>2>...
Surjeet Kumar Verma's user avatar
0 votes
1 answer
750 views

I recently went back to the String comparisons in Java and tried this: String s = "hello"; System.out.println(s == "hello"); System.out.println(s.equals("hello")); When ...
sfeng's user avatar
  • 105
1 vote
1 answer
84 views

I want to see the implementation of the Mandelbrot Set working (script provided by BruXy.regnet.cz), but one line of code is giving me problems to resolve. In the While-loop, a logic AND comparison is ...
Den's user avatar
  • 183
-1 votes
1 answer
160 views

I have a program in which I am plotting a function in the console, and I am iterating through a value of y which is a float. However, when this value is equal to zero, I would like to draw the axis. ...
Nasser Kessas's user avatar
1 vote
2 answers
59 views

I am writing a code that vaguely simulates a poker game, which at this point should output a "Players Hand", an "Opponents Hand" and a "Flop". Each card should only ...
Ma Wi's user avatar
  • 11
4 votes
2 answers
189 views

Say I have a container that uses a hardcoded pmr allocator to store data. What is the consensus among the C++ community: should operator==() compare equal on objects that only differ by their ...
glades's user avatar
  • 5,374
0 votes
2 answers
681 views

//TASK 5 PART 1 //Request input from user let x = Number(prompt("Enter a number:")); // using if...else if if (x % 7 === 0 && x % 11 === 0) { console.log ...
saf's user avatar
  • 33
0 votes
1 answer
140 views

I am very new to JavaScript, and so I am here to ask for help on how to make my code more efficient, using less lines of code, improve readability or if anybody spots any errors. I am always keen on ...
saf's user avatar
  • 33
9 votes
2 answers
386 views

I am learning and playing around with Python and I came up with the following test code (please be aware that I would not write productive code like that, but when learning new languages I like to ...
Markus Weninger's user avatar
2 votes
2 answers
228 views

On comparing '1' with '_' the answer I'm expecting is '1' < '_' because their Ascii values are 49 and 95 respectively. But the answer is the other way. For that matter, even ':' instead of '_' ...
Utkarsh Kajaria's user avatar
1 vote
1 answer
175 views

The following flawed code for a null pointer check compiles with some compilers but not with others (see godbolt): bool f() { char c; return &c > nullptr; } The offensive part is the ...
Peter - Reinstate Monica's user avatar
0 votes
2 answers
816 views

function sendEmails() { const sheet = getSpreadsheetApp() const sheetData = getSpreadsheetData(sheet).getValues(); const subjectline = "Weekly Breakdown for the week of - " var ...
Harikrishnan Kavungal's user avatar
1 vote
1 answer
101 views

Snippet struct A { int a; }; bool operator==(const A& lhs, const A& rhs) { return lhs.a == rhs.a; } template <typename T> bool operator==(const A& lhs, const T& rhs) { ...
Juergen's user avatar
  • 3,769
1 vote
1 answer
45 views

This works perfectly but I want to know that here I am checking only the most recent user input value(with their index number) with the randomly generated value and their lengths, but how can I check ...
Tahir Azad's user avatar
0 votes
1 answer
158 views

I know python2.7 allows comparison between different types. So the equality comparison between str and int will result in False. Can the comparison ever be true depending on the values of a and b? a =...
CodeTalker's user avatar
  • 1,831

1
2 3 4 5
16