Date: Sat, 4 Apr 2026 11:53:16 +0500
Sorry for the late reply( I was showering and using hair oil)
Sorry for my confusing reply, really sorry.
The short answer is:
NO
The long answer is:
The rules for templates would apply here, and concepts can be used to
further constraint the requirements and make any resulting errors readable,
so basically, it would work only if vector and list have the member
capacity.
***Correction on my private email:***
They also don't have reserve
Thank you for your feedback ❤️❤️❤️❤️❤️
Regards, Muneem
On Sat, 4 Apr 2026, 10:50 am Andre Kostur, <andre_at_[hidden]> wrote:
> 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());
> }
>
Sorry for my confusing reply, really sorry.
The short answer is:
NO
The long answer is:
The rules for templates would apply here, and concepts can be used to
further constraint the requirements and make any resulting errors readable,
so basically, it would work only if vector and list have the member
capacity.
***Correction on my private email:***
They also don't have reserve
Thank you for your feedback ❤️❤️❤️❤️❤️
Regards, Muneem
On Sat, 4 Apr 2026, 10:50 am Andre Kostur, <andre_at_[hidden]> wrote:
> 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());
> }
>
Received on 2026-04-04 06:53:33
