Skip to content

Allow initialization of PropertiesFile::Options using C++11 initializer list and C++20 designated initializer #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

l0ner
Copy link

@l0ner l0ner commented Aug 14, 2025

The presence of a default Ctor for PropertiesFile::Options, prevents initialization of this struct using C++11 Initializer List, or C++20 designated initializers.

This means that PropertiesFile::Option properties need to be set manually, every time referencing the variable that holds the Option resulting in quite repetitive code. Ie:

juce::PropertiesFile::Options userSettingsFileOptions;
userSettingsFileOptions.applicationName     = "MyApp";
userSettingsFileOptions.filenameSuffix      = ".bin";
userSettingsFileOptions.folderName          = "myAppSettingDir";
userSettingsFileOptions.osxLibrarySubFolder = "Application Support";
userSettingsFileOptions.storageFormat       = PropertiesFile::storeAsBinary;
// ...
juce::ApplicationProperties userSettings;
userSettings.setStorageParameters(userSettingsFileOptions);

While using the C++11 initializer list requires all aggregate member values to be specified in order, it results in a bit less repetitive code:

juce::ApplicationProperties userSettings;
userSettings.setStorageParameters(juce::PropertiesFile::Options {
    "MyApp",
    ".bin",
    "myAppSettingsDir",
    "Application Support",
    true,
    true,
    false,
    3000,
    PropertiesFile::StorageFormat::storeAsBinary
});

By allowing the use of C++20 designated initializer the code can be made terser (and more readable) than the one required when using C++11 initializer list.

juce::ApplicationProperties userSettings;
userSettings.setStorageParameters(juce::PropertiesFile::Options {
    .applicationName     = "MyApp",
    .filenameSuffix      = ".bin",
    .folderName          = "myAppSettingsDir",
    .osxLibrarySubFolder = "Application Support",
    .storageFormat       = juce::PropertiesFile::StorageFormat::storeAsBinary
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant