NREL / OpenStudio

OpenStudio is a cross-platform collection of software tools to support whole building energy modeling using EnergyPlus and advanced daylight analysis using Radiance.
https://www.openstudio.net/
Other
484 stars 185 forks source link

Swig `T boost::optional<T>::value_or(T default_value)` #5172

Closed jmarrec closed 2 months ago

jmarrec commented 2 months ago

Pull request overview

Swig T boost::optional<T>::value_or(T default_value). I think the semantics is nice.

This allows you to write something like

def get_optional(is_initialized)
  is_initialized ? OpenStudio::OptionalDouble.new(10.0) : OpenStudio::OptionalDouble.new()
end

val = get_optional(true).value_or(20.0)
raise unless val == 10.0
val = get_optional(false).value_or(20.0)
raise unless val == 20.0

Pull Request Author

Labels:

Review Checklist

This will not be exhaustively relevant to every PR.