Date: Tue, 31 Mar 2026 10:44:08 -0400
On Mon, Mar 30, 2026 at 4:48 PM Muneem via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Recently, I faced some issues in writing code that relied heavily on repetitive branching, which forced me to use AI. This proposal proposes techniques to counter this, in cases where the overhead of single dispatch is highly undesirable.
Have you considered that what you're trying to do is perhaps not an
effective way to implement whatever that is? And that there's probably
a better way that doesn't require using a `switch` in the middle of
various functions?
For example, let's take your initial code:
```
void push_multiple_to_container(const std::string string_to_read_from,
std::string::size_type* pos) {
switch(static_cast<where_to_push_enum>(
absolute_base::read_from_string<get_integer_for_size<sizeof(where_to_push_enum)>>))
{
case push_to_vector:
implementation_template_function_f(vector, read_content_to_push);
break;
case push_to_deque:
implementation_template_function_f(deque, read_content_to_push);
break;
// ... and so on
}
}
```
I don't see where `where_to_push_enum` comes from. Since you're doing
a `static_cast` to it, this is a type. I don't see a template header,
so I'm guessing that this is a member of a template class where
`where_to_push_enum` is provided as a template argument.
So it stands to reason that you could reduce this function to
something like this:
```
implementation_template_function_f(_get_container(), read_content_to_push);
```
Where `_get_container` has your switch/case statement and returns this
container. And the containers it can return are appropriate for
calling `implementation_template_function_f`.
<std-proposals_at_[hidden]> wrote:
>
> Recently, I faced some issues in writing code that relied heavily on repetitive branching, which forced me to use AI. This proposal proposes techniques to counter this, in cases where the overhead of single dispatch is highly undesirable.
Have you considered that what you're trying to do is perhaps not an
effective way to implement whatever that is? And that there's probably
a better way that doesn't require using a `switch` in the middle of
various functions?
For example, let's take your initial code:
```
void push_multiple_to_container(const std::string string_to_read_from,
std::string::size_type* pos) {
switch(static_cast<where_to_push_enum>(
absolute_base::read_from_string<get_integer_for_size<sizeof(where_to_push_enum)>>))
{
case push_to_vector:
implementation_template_function_f(vector, read_content_to_push);
break;
case push_to_deque:
implementation_template_function_f(deque, read_content_to_push);
break;
// ... and so on
}
}
```
I don't see where `where_to_push_enum` comes from. Since you're doing
a `static_cast` to it, this is a type. I don't see a template header,
so I'm guessing that this is a member of a template class where
`where_to_push_enum` is provided as a template argument.
So it stands to reason that you could reduce this function to
something like this:
```
implementation_template_function_f(_get_container(), read_content_to_push);
```
Where `_get_container` has your switch/case statement and returns this
container. And the containers it can return are appropriate for
calling `implementation_template_function_f`.
Received on 2026-03-31 14:44:20
