https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105838

--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> ---
Another significant part of the problem is that vector<string> doesn't have a
generic initializer_list constructor.  Adding

      template <typename __elt>
      _GLIBCXX20_CONSTEXPR
      vector(initializer_list<__elt> __l,
             const allocator_type& __a = allocator_type())
      : _Base(__a)
      {
        _M_range_initialize(__l.begin(), __l.end(),
                            random_access_iterator_tag());
      }

so that it can construct from initializer_list<const char *> makes the
construction into a simple loop over a static array.

Users can do this optimization manually by writing e.g.

  auto init = {
  "aahing", "aaliis", "aarrgh", "abacas", "abacus", "abakas", "abamps",
"abands", "abased", "abaser", "abases", "abasia",
  };
  const std::vector<std::string> lst (init.begin(), init.end());

and so using the (template) iterator constructor instead of the (non-template)
initializer_list constructor.  But that shouldn't be necessary.

Jonathan, has anyone suggested adding generic init_list constructors to the
container classes?

What do you think about doing the above translation in the compiler?  Is the
compiler allowed to do that?

Reply via email to