How to select matching audio input and output devices?

How do I ensure that in JUCE application, audio devices are using the same actual hardware device for both input and output channels?

On most audio interfaces both the input and output devices have identical names so in that case it would be easy to just compare their names and use the ones with matching names. But for example on Mac the standard input and output devices are called “Built-in Output” and “Built-in Microphone”. It’s not possible to simply check if the names of those input and output devices are the same.

So how do I make it so that when the user of JUCE application selects an audio output device, the software automatically selects the correct input device for it?

Below is the code I use to choose the input/output devices. All I would need to figure out which “output_audio_device_name” and “input_audio_device_name” to use so that they use the same hardware device.

    AudioDeviceManager::AudioDeviceSetup current_audio_setup = deviceManager.getAudioDeviceSetup();

    current_audio_setup.outputDeviceName = output_audio_device_name;
    current_audio_setup.inputDeviceName  = input_audio_device_name;
    current_audio_setup.sampleRate       = sample_rate;
    current_audio_setup.bufferSize       = audio_buffer_size;

    deviceManager.setAudioDeviceSetup(current_audio_setup, true);