With latest Xcode, how can I use a juce::Font in a std::map without getting deprecation warnings

Xcode 26.4

    std::map<juce::String, juce::Font> fonts;

    auto f = juce::Font (juce::FontOptions());
    fonts["foo"] = f;
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/usr/include/c++/v1/algorithm:1846:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/usr/include/c++/v1/__algorithm/copy.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/usr/include/c++/v1/__algorithm/copy_move_common.h:13:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/usr/include/c++/v1/__algorithm/unwrap_range.h:19:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/usr/include/c++/v1/__utility/pair.h:446:9: warning: 'Font' is deprecated: Use the constructor that takes a FontOptions argument [-Wdeprecated-declarations]
  446 |         second(std::forward<_Args2>(std::get<_I2>(__second_args))...) {}
      |         ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.4.sdk/usr/include/c++/v1/__utility/pair.h:225:9: note: in instantiation of function template specialization 'std::pair<const juce::String, juce::Font>::pair<juce::String &&, 0UL>' requested here
  225 |       : pair(__pc,

don’t use the operator [ ] but rather emplace or insert_or_assign

1 Like

You could use std::map<juce::String, juce::FontOptions> instead?