From 4c0f77c13e5e38b6fb4c4e2746a6f1adf373f290 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Dec 2020 06:43:59 -0800 Subject: Remove some unnecessary constructors --- common/aloptional.h | 31 ++++++++----------------------- common/strutils.cpp | 6 ++++-- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/common/aloptional.h b/common/aloptional.h index f19bc288..e48711f2 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -45,27 +45,11 @@ public: explicit optional(in_place_t, Args&& ...args) : mHasValue{true} , mValue{std::forward(args)...} { } - template&, Args...>::value)> - explicit optional(in_place_t, std::initializer_list il, Args&& ...args) - : mHasValue{true}, mValue{il, std::forward(args)...} - { } - template::value && - !std::is_same::type, in_place_t>::value && - !std::is_same::type, optional>::value && - std::is_constructible::value)> - constexpr explicit optional(U&& value) : mHasValue{true}, mValue{std::forward(value)} - { } - template::value && - !std::is_same::type, in_place_t>::value && - !std::is_same::type, optional>::value && - !std::is_constructible::value)> - constexpr optional(U&& value) : mHasValue{true}, mValue{std::forward(value)} - { } ~optional() { if(mHasValue) al::destroy_at(std::addressof(mValue)); } optional& operator=(nullopt_t) noexcept { reset(); return *this; } - template::value && std::is_copy_assignable::value)> - optional& operator=(const optional &rhs) + std::enable_if_t::value && std::is_copy_assignable::value, + optional&> operator=(const optional &rhs) { if(!rhs) reset(); @@ -75,8 +59,8 @@ public: DoConstruct(*rhs); return *this; } - template::value && std::is_move_assignable::value)> - optional& operator=(optional&& rhs) + std::enable_if_t::value && std::is_move_assignable::value, + optional&> operator=(optional&& rhs) { if(!rhs) reset(); @@ -86,12 +70,13 @@ public: DoConstruct(std::move(*rhs)); return *this; } - template::value && + template + std::enable_if_t::value && std::is_assignable::value && !std::is_same::type, optional>::value && (!std::is_same::type, T>::value || - !std::is_scalar::value))> - optional& operator=(U&& rhs) + !std::is_scalar::value), + optional&> operator=(U&& rhs) { if(*this) mValue = std::forward(rhs); diff --git a/common/strutils.cpp b/common/strutils.cpp index 870a0ed3..18c4947a 100644 --- a/common/strutils.cpp +++ b/common/strutils.cpp @@ -46,7 +46,8 @@ namespace al { al::optional getenv(const char *envname) { const char *str{std::getenv(envname)}; - if(str && str[0] != '\0') return str; + if(str && str[0] != '\0') + return al::make_optional(str); return al::nullopt; } @@ -54,7 +55,8 @@ al::optional getenv(const char *envname) al::optional getenv(const WCHAR *envname) { const WCHAR *str{_wgetenv(envname)}; - if(str && str[0] != L'\0') return str; + if(str && str[0] != L'\0') + return al::make_optional(str); return al::nullopt; } #endif -- cgit v1.2.3