Unverified Commit f271e90e authored by Mateusz Szychowski (Muttley)'s avatar Mateusz Szychowski (Muttley) Committed by GitHub

optional: make Some and None constructors implicit (#718)

* optional: reenable implicit constructors when using Some and None

* CMake: suppress noExplicitConstructor for optional.h

implicit constructors are intentional there
parent 2bfdb96b
......@@ -39,6 +39,7 @@ if (PISTACHE_BUILD_TESTS)
"-DCPPCHECK"
"--suppress=*:${PROJECT_SOURCE_DIR}/third-party*"
"--suppress=*:${PROJECT_SOURCE_DIR}/tests*"
"--suppress=noExplicitConstructor:include/pistache/optional.h"
)
else()
message("-- Cppcheck not found")
......
......@@ -125,12 +125,12 @@ public:
}
template <typename U>
explicit Optional(types::Some<U> some) : none_flag(NoneMarker) {
Optional(types::Some<U> some) : none_flag(NoneMarker) {
static_assert(std::is_same<T, U>::value || std::is_convertible<U, T>::value,
"Types mismatch");
from_some_helper(std::move(some), types::is_move_constructible<U>());
}
explicit Optional(types::None) { none_flag = NoneMarker; }
Optional(types::None) { none_flag = NoneMarker; }
template <typename U> Optional<T> &operator=(types::Some<U> some) {
static_assert(std::is_same<T, U>::value || std::is_convertible<U, T>::value,
......
......@@ -99,7 +99,7 @@ TEST(optional, copy_assignment_operator_none) {
Optional<bool> value(Pistache::None());
EXPECT_TRUE(value.isEmpty());
Optional<bool> assigned = Pistache::Optional<bool>(Pistache::None());
Optional<bool> assigned = Pistache::None();
EXPECT_TRUE(assigned.isEmpty());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment