This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

3786. Flat maps' deduction guide needs to default Allocator to be useful

Section: 24.6.9.2 [flat.map.defn], 24.6.10.2 [flat.multimap.defn] Status: WP Submitter: Johel Ernesto Guerrero Peña Opened: 2022-09-25 Last modified: 2023-02-13

Priority: 2

View all issues with WP status.

Discussion:

This originated from the editorial issue #5800.

P0429R9 added some deduction guides with a non-defaulted Allocator template parameter and a corresponding function parameter that is defaulted. Since the template parameter Allocator is not defaulted, these deduction guides are never used.

[2022-09-28; LWG telecon]

We should not just ignore the allocator, it should be rebound and used for the two container types.

Previous resolution [SUPERSEDED]:

This wording is relative to N4917.

  1. Modify 24.6.9.2 [flat.map.defn], class template flat_map synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<range-key-type<R>>,
             class Allocator = allocator<void>>
      flat_map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_map<range-key-type<R>, range-mapped-type<R>, Compare>;
    […]
    
  2. Modify 24.6.10.2 [flat.multimap.defn], class template flat_multimap synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<range-key-type<R>>,
             class Allocator = allocator<void>>
      flat_multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_multimap<range-key-type<R>, range-mapped-type<R>, Compare>;
    […]
    

[2022-10-19; Jonathan provides improved wording]

Previous resolution [SUPERSEDED]:

This wording is relative to N4917.

  1. Modify 24.6.1 [container.adaptors.general] as indicated:

    -8- The following exposition-only alias templates may appear in deduction guides for container adaptors:

    template<class Container>
      using cont-key-type =                                // exposition only
        remove_const_t<typename Container::value_type::first_type>;
    template<class Container>
      using cont-mapped-type =                             // exposition only
        typename Container::value_type::second_type;
    template<class Allocator, class T>
      using alloc-rebind =                             // exposition only
        typename allocator_traits<Allocator>::template rebind_alloc<T>;
    
    
  2. Modify 24.6.9.2 [flat.map.defn], class template flat_map synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<range-key-type<R>>,
             class Allocator = allocator<void>>
      flat_map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_map<range-key-type<R>, range-mapped-type<R>, Compare,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_map(from_range_t, R&&, Allocator)
        -> flat_map<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>;
    […]
    
  3. Modify 24.6.10.2 [flat.multimap.defn], class template flat_multimap synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<range-key-type<R>>,
             class Allocator = allocator<void>>
      flat_multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_multimap<range-key-type<R>, range-mapped-type<R>, Compare,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_multimap(from_range_t, R&&, Allocator)
        -> flat_multimap<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>;
    […]
    
  4. Modify 24.6.11.2 [flat.set.defn], class template flat_set synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
             class Allocator = allocator<ranges::range_value_t<R>>>
      flat_set(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_set<ranges::range_value_t<R>, Compare,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_set(from_range_t, R&&, Allocator)
        -> flat_set<ranges::range_value_t<R>, less<ranges::range_value_t<R>>,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    […]
    
  5. Modify 24.6.12.2 [flat.multiset.defn], class template flat_multiset synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
             class Allocator = allocator<ranges::range_value_t<R>>>
      flat_multiset(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_multiset<ranges::range_value_t<R>, Compare,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_multiset(from_range_t, R&&, Allocator)
        -> flat_multiset<ranges::range_value_t<R>, less<ranges::range_value_t<R>>,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    […]
    

[2023-01-11; Jonathan Wakely provides improved wording]

During LWG telecon Tim pointed out that because allocator<void> does not meet the Cpp17Allocator requirements, it might not "qualify as an allocator" and so would cause the deduction guides to not participate in overload resolution, as per 24.6.1 [container.adaptors.general] p6 (6.4). Use allocator<byte> instead.

[Issaquah 2023-02-07; LWG]

Edited proposed resolution to fix missing > in guides for maps. Move to Immediate for C++23

[2023-02-13 Status changed: Immediate → WP.]

Proposed resolution:

This wording is relative to N4917.

  1. Modify 24.6.1 [container.adaptors.general] as indicated:

    -8- The following exposition-only alias template may appear in deduction guides for container adaptors:

    template<class Allocator, class T>
      using alloc-rebind =                                 // exposition only
        typename allocator_traits<Allocator>::template rebind_alloc<T>;
    
    
  2. Modify 24.6.9.2 [flat.map.defn], class template flat_map synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<range-key-type<R>>,
             class Allocator = allocator<byte>>
      flat_map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_map<range-key-type<R>, range-mapped-type<R>, Compare,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_map(from_range_t, R&&, Allocator)
        -> flat_map<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>>;
    […]
    
  3. Modify 24.6.10.2 [flat.multimap.defn], class template flat_multimap synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<range-key-type<R>>,
             class Allocator = allocator<byte>>
      flat_multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_multimap<range-key-type<R>, range-mapped-type<R>, Compare,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_multimap(from_range_t, R&&, Allocator)
        -> flat_multimap<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>,
             vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>>,
             vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>>;
    […]
    
  4. Modify 24.6.11.2 [flat.set.defn], class template flat_set synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
             class Allocator = allocator<ranges::range_value_t<R>>>
      flat_set(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_set<ranges::range_value_t<R>, Compare,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_set(from_range_t, R&&, Allocator)
        -> flat_set<ranges::range_value_t<R>, less<ranges::range_value_t<R>>,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    […]
    
  5. Modify 24.6.12.2 [flat.multiset.defn], class template flat_multiset synopsis, as indicated:

    […]
    template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
             class Allocator = allocator<ranges::range_value_t<R>>>
      flat_multiset(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
        -> flat_multiset<ranges::range_value_t<R>, Compare,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    
    template<ranges::input_range R, class Allocator>
      flat_multiset(from_range_t, R&&, Allocator)
        -> flat_multiset<ranges::range_value_t<R>, less<ranges::range_value_t<R>>,
             vector<ranges::range_value_t<R>, alloc-rebind<Allocator, ranges::range_value_t<R>>>>;
    […]