Programming questions are off-topic here. Do not ask questions about how to write code in C++. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.
Questions tagged [c++]
92 questions
8
votes
4 answers
How does the linker know where to look for a function implementation in C++?
I am currently learning about how the compilation and linking works in C++. I think I kinda get how the compiler works, and that for a file to fully compile you don't need to have function implementations, but only declarations. It is the linker's…
artas2357
- 183
- 1
- 6
6
votes
1 answer
How are extremely large integers stored and implemented in programming languages?
We have data types like int and long etc. which can store just a few bytes of integers.
But when we are implementing cryptographic algorithms like RSA or Elliptic Curves, we know that the key values are usually 1024 bits long.
How is this…
Yuv
- 139
- 7
6
votes
1 answer
Where are C++ templates inside of the lambda cube?
C++ templates have type variables and can express lambdas, so they must have System F embedded. But is that exactly where they are located in the lambda cube? Can C++ templates produce new types or express dependent types?
(I originally posted this…
ArtIntoNihonjin.
- 71
- 2
- 11
5
votes
4 answers
How do you find a hash function that respects a custom equality function?
I've been tasked with hashing arbitrary types in C++, with the caveat that A == B implies hash(A) == hash(B) even if equality of A and B is determined by a custom equality function ==.
For simplicity we can assume that == is an equivalence relation.…
etha7
- 51
- 5
4
votes
0 answers
Subtype Check with Type DAG
Trying to understand how compiler/static-type-checker checks for subtyping, I run into 2 problems.
1. Reachability in DAG
Since both Python/C++ support multiple inheriatnce, the types can be represented as a DAG.
A C
| / \
B D
|\ |
E F /
| …
mq7
- 141
- 1
4
votes
1 answer
Why are struct and class essentially the same in C++?
struct and class in C++ are nearly identical (as covered for example here).
But why is this so? What did happen when C++ was developed and eventually standardized, that struct was allowed to define a full OOP class, yet class keyword was also added?…
hyde
- 153
- 1
- 9
4
votes
1 answer
Linked list: advantages of preventing movement of nodes and invalidating iterators on add/remove
C++ and Java include native classes for linked lists, C++ std::list and Java LinkedList
For C++ std::list, nodes can be "moved" within a list, or from list to list (if the lists are compatible), via std::list::splice(), which in turn is used by…
rcgldr
- 364
- 2
- 12
3
votes
1 answer
What type of function is main()?
As the functions are of 2 type:1.Pre-defined/library functions,2.User defined functions.
What type of function is main() function?
This doubt comes in my mind while writing a program we define the main() function as we do the others.
Please help!!!
Harsh Kumar
- 232
- 2
- 13
3
votes
4 answers
Is there an elegant algorithm for applying multiple simultaneous search-and-replace operations to a string?
The operation I'm interested in is a slight twist on your standard search-and-replace operation, in that instead of a single pair of arguments (replaceme and withme), it takes a keyed set of N [before, after] pairs as an argument, and for each pair…
Jeremy Friesner
- 267
- 2
- 7
3
votes
0 answers
How to detect when to use radix sort in runtime
I'm implementing a stable integer sorting algorithm, I've chosen radix sort. I've tested LSD vs MSD implementation, wrote MSD/LSD hybrid implementation to reduce bandwidth pressure. The repo is here: https://github.com/KirillLykov/int-sort-bmk
Now…
Kirill Lykov
- 131
- 3
3
votes
1 answer
Why is the address-of operator in C/C++ represented with the "&" symbol?
I've started learning C++, and I know a little bit of C. Something that always struck me as somewhat off was that the address-of operator is represented with the seemingly random ampersand (&) symbol instead of, say, the "at" symbol (@). Is there…
Nat H
- 31
- 2
3
votes
1 answer
C++ STL: How does the distance() method work for a set/ multiset (stored internally as a self balancing tree)?
I'm working on the problem: Count smaller elements on right side using Set in C++ STL
The solution is to add each element to the set and then to count the elements on the left, the distance function is called.
This is the algo:
1. Traverse the array…
user248884
- 245
- 3
- 9
3
votes
1 answer
numerically stable log1pexp calculation
What are good approximations for computing log1pexp for single precision and double precision floating point numbers?
Note: log1pexp(x) is log(1 + exp(x))
I have found few implementations of log1pexp for double precision but they don't provide an…
Yashas
- 275
- 1
- 10
3
votes
0 answers
Summary of types of equivalence and equality in type theory, with notations and examples
Coming from non-computer science background, I am trying to understand the different types of equivalence and equality usually used in type theory. Ideally, I am looking for clear definitions and notations (ie the symbols commonly used)…
Vincent
- 221
- 1
- 7
2
votes
2 answers
Compare each array $i$ member to all array $j$ member where $(i > j)$ , in time less than $O(n^2)$
I am new to algorithms so sorry to ask simple question
I am working on a problem which is about array of integers, my solution is right but not good enough, because I have time exceeded exception on codeforces. I think solution where solution's time…
Nika Kurashvili
- 121
- 3