diff options
author | Chris Robinson <[email protected]> | 2019-07-01 17:25:58 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-07-01 17:25:58 -0700 |
commit | 6bb0edf0a57bdb95c017db986f76eddbc80857e1 (patch) | |
tree | dc2b0677dc338843c585b2499136d16b56e9d1f0 | |
parent | 53c13de5ce6467f15cc12c855418ed2589a8508a (diff) |
Create and use a make_optional method
-rw-r--r-- | Alc/alc.cpp | 2 | ||||
-rw-r--r-- | Alc/alconfig.cpp | 12 | ||||
-rw-r--r-- | OpenAL32/alBuffer.cpp | 2 | ||||
-rw-r--r-- | common/aloptional.h | 12 |
4 files changed, 20 insertions, 8 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 521da6bc..df272c2a 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1373,7 +1373,7 @@ static al::optional<DevFmtPair> DecomposeDevFormat(ALenum format) for(const auto &item : list) { if(item.format == format) - return al::optional<DevFmtPair>{{item.channels, item.type}}; + return al::make_optional(DevFmtPair{item.channels, item.type}); } return al::nullopt; diff --git a/Alc/alconfig.cpp b/Alc/alconfig.cpp index b6e406fd..5f5f9149 100644 --- a/Alc/alconfig.cpp +++ b/Alc/alconfig.cpp @@ -497,7 +497,7 @@ al::optional<std::string> ConfigValueStr(const char *devName, const char *blockN const char *val = GetConfigValue(devName, blockName, keyName, ""); if(!val[0]) return al::nullopt; - return al::optional<std::string>{val}; + return al::make_optional<std::string>(val); } al::optional<int> ConfigValueInt(const char *devName, const char *blockName, const char *keyName) @@ -505,7 +505,7 @@ al::optional<int> ConfigValueInt(const char *devName, const char *blockName, con const char *val = GetConfigValue(devName, blockName, keyName, ""); if(!val[0]) return al::nullopt; - return al::optional<int>{static_cast<int>(std::strtol(val, nullptr, 0))}; + return al::make_optional(static_cast<int>(std::strtol(val, nullptr, 0))); } al::optional<unsigned int> ConfigValueUInt(const char *devName, const char *blockName, const char *keyName) @@ -513,7 +513,7 @@ al::optional<unsigned int> ConfigValueUInt(const char *devName, const char *bloc const char *val = GetConfigValue(devName, blockName, keyName, ""); if(!val[0]) return al::nullopt; - return al::optional<unsigned int>{static_cast<unsigned int>(std::strtoul(val, nullptr, 0))}; + return al::make_optional(static_cast<unsigned int>(std::strtoul(val, nullptr, 0))); } al::optional<float> ConfigValueFloat(const char *devName, const char *blockName, const char *keyName) @@ -521,7 +521,7 @@ al::optional<float> ConfigValueFloat(const char *devName, const char *blockName, const char *val = GetConfigValue(devName, blockName, keyName, ""); if(!val[0]) return al::nullopt; - return al::optional<float>{std::strtof(val, nullptr)}; + return al::make_optional(std::strtof(val, nullptr)); } al::optional<bool> ConfigValueBool(const char *devName, const char *blockName, const char *keyName) @@ -529,9 +529,9 @@ al::optional<bool> ConfigValueBool(const char *devName, const char *blockName, c const char *val = GetConfigValue(devName, blockName, keyName, ""); if(!val[0]) return al::nullopt; - return al::optional<bool>{ + return al::make_optional( strcasecmp(val, "true") == 0 || strcasecmp(val, "yes") == 0 || - strcasecmp(val, "on") == 0 || atoi(val) != 0}; + strcasecmp(val, "on") == 0 || atoi(val) != 0); } int GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, int def) diff --git a/OpenAL32/alBuffer.cpp b/OpenAL32/alBuffer.cpp index 8b081b78..a6ed98cc 100644 --- a/OpenAL32/alBuffer.cpp +++ b/OpenAL32/alBuffer.cpp @@ -402,7 +402,7 @@ al::optional<DecompResult> DecomposeUserFormat(ALenum format) for(const auto &fmt : UserFmtList) { if(fmt.format == format) - return al::optional<DecompResult>{{fmt.channels, fmt.type}}; + return al::make_optional(DecompResult{fmt.channels, fmt.type}); } return al::nullopt; } diff --git a/common/aloptional.h b/common/aloptional.h index a4b37212..8524a2e2 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -139,6 +139,18 @@ private: }; }; +template<typename T> +inline optional<typename std::decay<T>::type> make_optional(T&& arg) +{ return optional<typename std::decay<T>::type>{in_place, std::forward<T>(arg)}; } + +template<typename T, typename... Args> +inline optional<T> make_optional(Args&& ...args) +{ return optional<T>{in_place, std::forward<Args>(args)...}; } + +template<typename T, typename U, typename... Args> +inline optional<T> make_optional(std::initializer_list<U> il, Args&& ...args) +{ return optional<T>{in_place, il, std::forward<Args>(args)...}; } + #undef REQUIRES } // namespace al |