From 328d832940ca76dc5d601ce00e4229556b077a18 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 16 Jan 2019 11:21:03 +0100 Subject: options/value: disallow const, volatile, and reference types --- options/value.hpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/options/value.hpp b/options/value.hpp index daf87378..3478e842 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -35,16 +35,15 @@ namespace options::detail { namespace options { -template +template class value final : public value_ { - using t = remove_cvref_t; + static_assert(std::is_same_v>); const t def; - using traits = detail::value_traits; cc_noinline - t get() const noexcept + auto get() const noexcept { if (!b->contains(self_name)) return traits::pass_value(def); @@ -96,20 +95,20 @@ public: emit valueChanged(traits::storage_from_value(get())); } - value& operator=(t&& datum) noexcept + auto& operator=(t&& datum) noexcept { store_variant(traits::qvariant_from_value(traits::pass_value(datum))); return *this; } - value& operator=(const t& datum) noexcept + auto& operator=(const t& datum) noexcept { t copy{datum}; *this = std::move(copy); return *this; } - value& operator=(const value& datum) noexcept + auto& operator=(const value& datum) noexcept { *this = *datum; return *this; @@ -122,7 +121,7 @@ public: { } - value(const value& other) noexcept : value{other.b, other.self_name, other.def} {} + value(const value& other) noexcept : value{other.b, other.self_name, other.def} {} t default_value() const { @@ -136,21 +135,21 @@ public: operator t() const { return get(); } - template - explicit cc_forceinline operator w() const { return to(); } + template + explicit cc_forceinline operator u() const { return to(); } auto operator->() const noexcept { - return detail::dereference_wrapper{get()}; + return detail::dereference_wrapper{get()}; } - cc_forceinline t operator()() const noexcept { return get(); } - cc_forceinline t operator*() const noexcept { return get(); } + cc_forceinline auto operator()() const noexcept { return get(); } + cc_forceinline auto operator*() const noexcept { return get(); } - template - w to() const noexcept + template + u to() const noexcept { - return static_cast(get()); + return static_cast(get()); } }; -- cgit v1.2.3