teslamotors / fixed-containers

C++ Fixed Containers
MIT License
361 stars 31 forks source link

Add size deduction for FixedMap, FixedSet & FixedVector #12

Closed SGauvin closed 1 year ago

SGauvin commented 1 year ago

Add functions make_fixed_map, make_fixed_set and make_fixed_vector to deduce the size of their container at compile time.

When it's known that a container won't need to grow at runtime, it is now possible to create the container without specifying its maximum size, and its maximum size will be deduced to be the number of items passed to the make_fixed_[map/set/vector] function.

The SIZE template parameter in these functions has been pushed down as far as possible to make it possible to change other template parameters without having to specify the size.

Before:

FixedVector<int, 3> vector{1, 2, 3};

After:

auto v = make_fixed_vector<int>({1, 2, 3});

And now even the type can be deduced:

auto v = make_fixed_vector({1, 2, 3});
alexkaratarakis commented 1 year ago

Thank you!