Date: Sat, 4 Apr 2026 05:50:46 +0000
On Sat, Apr 4, 2026 at 5:21 AM Muneem <itfllow123_at_[hidden]> wrote:
>
> How does the compiler know what's gonna happen at runtime?
> The compiler will of course not no a lot on what's gonna happen at runtime, but it can branch or do whatever it sees fit to generate code to find out what gonna happen(the index) at time using the techniques explained below:
[snip a bunch of compiler theory]
Let's try this again:
Should the compiler accept the following program (with some syntax to
tell return_index_chosen about vdata and ldata, and appropriate
includes/imports)?
std::vector<int> vdata;
std::list<int> ldata;
int main(int argc, char *[]) {
srand(time(nullptr));
auto & x = return_index_chosen(rand() % 2);
std::print("{0}\n", x.capacity());
}
>
> How does the compiler know what's gonna happen at runtime?
> The compiler will of course not no a lot on what's gonna happen at runtime, but it can branch or do whatever it sees fit to generate code to find out what gonna happen(the index) at time using the techniques explained below:
[snip a bunch of compiler theory]
Let's try this again:
Should the compiler accept the following program (with some syntax to
tell return_index_chosen about vdata and ldata, and appropriate
includes/imports)?
std::vector<int> vdata;
std::list<int> ldata;
int main(int argc, char *[]) {
srand(time(nullptr));
auto & x = return_index_chosen(rand() % 2);
std::print("{0}\n", x.capacity());
}
Received on 2026-04-04 05:51:00
