Fix for invalid Optional constructor 16/152316/2
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 25 Sep 2017 15:27:09 +0000 (17:27 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Mon, 25 Sep 2017 15:31:00 +0000 (17:31 +0200)
Fix for invalid Optional constructor, where Optional<int> a = {} would cause object a to be initialized with 0
value, rather than empty Optional.

Change-Id: I84c0f4fcd5da2bca77cde411c016068e3df6e605

src/Optional.hpp

index 2f7903e..6819bda 100644 (file)
@@ -125,13 +125,13 @@ public:
                return *this;
        }
 
-       template <typename U = A>
-       typename std::enable_if <
-       !std::is_same<typename std::decay<U>::type, Optional<A>>::value &&
-                       std::is_constructible<A, U>::value &&
-                       std::is_assignable<A &, U>::value &&
-                       (!std::is_scalar<A>::value || !std::is_same<typename std::decay<U>, A>::value)
-                       , Optional & >::type operator = (U && a)
+       template < class U, class = typename std::enable_if
+                          <
+                                  std::is_same<typename std::remove_reference<U>::type, A>::value &&
+                                  std::is_constructible<A, U>::value &&
+                                  std::is_assignable<A &, U>::value
+                                  >::type
+                          > Optional & operator = (U && a)
        {
                if (hasValue)
                        place = std::forward<U>(a);