From cde00f55da5c4d6daf1934ab13ec8423610c9703 Mon Sep 17 00:00:00 2001 From: David Beck Date: Mon, 8 Oct 2018 13:30:36 +0100 Subject: IVGCVSW-1975 : total removal of boost::optional from the public interface Change-Id: Ib38a6216ebcdc350c75c028951b3f18f36a2f6b7 --- include/armnn/Optional.hpp | 62 ++++++++++++++++++++++++++++------------- src/armnn/test/OptionalTest.cpp | 4 +++ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/include/armnn/Optional.hpp b/include/armnn/Optional.hpp index 47afca87b5..e55702d915 100644 --- a/include/armnn/Optional.hpp +++ b/include/armnn/Optional.hpp @@ -8,8 +8,6 @@ #include #include -#include - // Optional is a drop in replacement for std::optional until we migrate // to c++-17. Only a subset of the optional features are implemented that // we intend to use in ArmNN. @@ -25,9 +23,6 @@ // - value() returns a reference to the held object // -// There is a deprecated and limited support for boost::optional in this class, -// which will be removed in the 19.02 release. - namespace armnn { @@ -35,7 +30,6 @@ namespace armnn // to have default value for an Optional in a function declaration. struct EmptyOptional {}; - // OptionalBase is the common functionality between reference and non-reference // optional types. class OptionalBase @@ -65,6 +59,28 @@ protected: bool m_HasValue; }; +struct HasGetMemberFunction +{ + template + static auto Check(T* p) -> decltype(p->get(), std::true_type()); + + template + static auto Check(...) -> std::false_type; +}; + +// +// Predicate checking for boost::optional compatibility +// +template +struct CheckBoostOptionalSignature +{ + using ResultType = decltype(HasGetMemberFunction::Check(0)); + + static constexpr bool Result() { + return std::is_same::value; + } +}; + // // The default implementation is the non-reference case. This // has an unsigned char array for storing the optional value which @@ -91,8 +107,11 @@ public: *this = other; } - // temporary support for limited conversion from boost - OptionalReferenceSwitch(const boost::optional& other) + // enable construction from types that matches the CheckBoostOptionalSignature + // predicate + template ::Result()>> + OptionalReferenceSwitch(const O& other) : Base{} { *this = other; @@ -116,21 +135,24 @@ public: return *this; } - // temporary support for limited conversion from boost - OptionalReferenceSwitch& operator=(const boost::optional& other) + OptionalReferenceSwitch& operator=(EmptyOptional) { reset(); - if (other.is_initialized()) - { - Construct(other.get()); - } - return *this; } - OptionalReferenceSwitch& operator=(EmptyOptional) + // enable copying from types that matches the CheckBoostOptionalSignature + // predicate + template ::Result()>> + OptionalReferenceSwitch& operator=(const O& other) { reset(); + if (other) + { + Construct(other.get()); + } + return *this; } @@ -267,13 +289,15 @@ class Optional final : public OptionalReferenceSwitch::valu public: using BaseSwitch = OptionalReferenceSwitch::value, T>; - Optional(const T& value) : BaseSwitch{value} {} Optional() noexcept : BaseSwitch{} {} + Optional(const T& value) : BaseSwitch{value} {} Optional(EmptyOptional empty) : BaseSwitch{empty} {} Optional(const Optional& other) : BaseSwitch{other} {} + Optional(const BaseSwitch& other) : BaseSwitch{other} {} - // temporary support for limited conversion from boost - Optional(const boost::optional& other) : BaseSwitch{other} {} + template ::Result()>> + Optional(const O& other) : BaseSwitch{other} {} }; } diff --git a/src/armnn/test/OptionalTest.cpp b/src/armnn/test/OptionalTest.cpp index 87fd156ece..a869c7e191 100644 --- a/src/armnn/test/OptionalTest.cpp +++ b/src/armnn/test/OptionalTest.cpp @@ -111,6 +111,10 @@ BOOST_AUTO_TEST_CASE(BoostCompatibilityTests) BoostCompatibilityTester(armnn::Optional(), false, ""); BoostCompatibilityTester(armnn::Optional("Hello World"), true, "Hello World"); + // verify boost signature selector + BOOST_TEST(armnn::CheckBoostOptionalSignature>::Result() == true); + BOOST_TEST(armnn::CheckBoostOptionalSignature>::Result() == false); + // the real thing is to see that we can pass a boost::optional in place // of an ArmNN Optional boost::optional empty; -- cgit v1.2.1