tzlaine / flat_map

flat_map standardization proposal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deduction guides taking `Container` need to be completely re-thought

Quuxplusone opened this issue · comments

From P1222R6:

  template <class Container, class Allocator>
    flat_set(Container, Allocator)
      -> flat_set<@\placeholder{cont-value-type}@<Container>>;

This deduction guide is suspect because it takes an Allocator parameter and drops it on the floor. For example,

std::polymorphic_allocator<int> a;
auto fs = std::flat_set(std::pmr::vector{1,2,3}, a);

will end up deducing

std::flat_set<int> fs = std::flat_set<int>(std::pmr::vector{1,2,3}, a);

and then of course that doesn't compile.
Comparing the signature of this guide to the guides for stack and queue, we see that if this guide exists at all, it should really look like

  template <class Container, class Allocator>
    flat_set(Container, Allocator)
      -> flat_set<@\placeholder{cont-value-type}@<Container>,
                   std::less<@\placeholder{cont-value-type}@<Container>>,
                   Container>;

so that the above example would end up deducing

std::flat_set<int, std::less<int>, std::pmr::vector<int>> fs = std::flat_set<int, std::less<int>, std::pmr::vector<int>>(std::pmr::vector{1,2,3}, a);

But that's a major change, in that

auto fs2 = std::flat_set{1,2,3};

would no longer compile at all.

So you need to decide: should flat_set{1,2,3} have the "obvious" meaning, in the same way that std::set{1,2,3} does? Or should it be ill-formed, in the same way that std::stack{1,2,3} is?