| 4271 | |
| 4272 | template <typename T> |
| 4273 | TOML_NODISCARD |
| 4274 | auto value_or(T&& default_value) const noexcept(impl::value_retrieval_is_nothrow<T>) |
| 4275 | { |
| 4276 | using namespace ::toml::impl; |
| 4277 | |
| 4278 | static_assert(!is_wide_string<T> || TOML_ENABLE_WINDOWS_COMPAT, |
| 4279 | "Retrieving values as wide-character strings is only " |
| 4280 | "supported on Windows with TOML_ENABLE_WINDOWS_COMPAT enabled."); |
| 4281 | |
| 4282 | if constexpr (is_wide_string<T>) |
| 4283 | { |
| 4284 | #if TOML_ENABLE_WINDOWS_COMPAT |
| 4285 | |
| 4286 | if (node_) |
| 4287 | return node_->value_or(static_cast<T&&>(default_value)); |
| 4288 | return std::wstring{ static_cast<T&&>(default_value) }; |
| 4289 | |
| 4290 | #else |
| 4291 | |
| 4292 | static_assert(impl::dependent_false<T>, "Evaluated unreachable branch!"); |
| 4293 | |
| 4294 | #endif |
| 4295 | } |
| 4296 | else |
| 4297 | { |
| 4298 | using value_type = |
| 4299 | std::conditional_t<std::is_pointer_v<std::decay_t<T>>, |
| 4300 | std::add_pointer_t<std::add_const_t<std::remove_pointer_t<std::decay_t<T>>>>, |
| 4301 | std::decay_t<T>>; |
| 4302 | |
| 4303 | if (node_) |
| 4304 | return node_->value_or(static_cast<T&&>(default_value)); |
| 4305 | if constexpr (std::is_pointer_v<value_type>) |
| 4306 | return value_type{ default_value }; |
| 4307 | else |
| 4308 | return static_cast<T&&>(default_value); |
| 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | template <typename T> |
| 4313 | TOML_PURE_INLINE_GETTER |