Boost logo

Boost :

From: Julien Blanc (julien.blanc_at_[hidden])
Date: 2022-06-03 07:19:32


Le 2022-06-03 08:44, Richard Hodges via Boost a écrit :
> On Fri, 3 Jun 2022 at 08:31, Julien Blanc via Boost
> <boost_at_[hidden]>
> wrote:
>
> Are you able to provide one or two motivating use cases? i.e. scenarios
> in
> which I would strongly prefer to use this library rather than a
> std::array
> and static_cast?

You mean, in addition to
https://github.com/julien-Blanc-tgcm/indexed_array#sample-use-cases ?

Another benefit that i did not speak of is that you get type safety for
the index. i.e. you cannot use a wrongly typed index:

indexed_array<char const*, user_messages> messages;
std::array<char const*, nb_user_messages> messages_arr;
// ...
play_message(messages_arr[static_cast<int>(tech_message::goon)]); //
boom at runtime
play_message(messages[tech_message::goon]); // fails to compile

I also find the code clearer (the static_cast just adds noise in my
opinion), but that would be a matter of taste.

Regards,

Julien


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk