diff options
author | David Beck <david.beck@arm.com> | 2018-10-08 13:30:36 +0100 |
---|---|---|
committer | Matthew Bentham <matthew.bentham@arm.com> | 2018-10-10 16:16:58 +0100 |
commit | cde00f55da5c4d6daf1934ab13ec8423610c9703 (patch) | |
tree | fa987eabbc2c1ecb9098d5af92626b193c7b1be3 | |
parent | d6c10ed456eb6d8f2569f9bebefe915c1e5951b7 (diff) | |
download | armnn-cde00f55da5c4d6daf1934ab13ec8423610c9703.tar.gz |
IVGCVSW-1975 : total removal of boost::optional from the public interface
Change-Id: Ib38a6216ebcdc350c75c028951b3f18f36a2f6b7
-rw-r--r-- | include/armnn/Optional.hpp | 62 | ||||
-rw-r--r-- | 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 <type_traits> #include <cstring> -#include <boost/optional.hpp> - // 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 <class T> + static auto Check(T* p) -> decltype(p->get(), std::true_type()); + + template <class T> + static auto Check(...) -> std::false_type; +}; + +// +// Predicate checking for boost::optional compatibility +// +template <typename T> +struct CheckBoostOptionalSignature +{ + using ResultType = decltype(HasGetMemberFunction::Check<T>(0)); + + static constexpr bool Result() { + return std::is_same<std::true_type, ResultType>::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<T>& other) + // enable construction from types that matches the CheckBoostOptionalSignature + // predicate + template <typename O, + typename = std::enable_if_t<CheckBoostOptionalSignature<O>::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<T>& 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 <typename O, + typename = std::enable_if_t<CheckBoostOptionalSignature<O>::Result()>> + OptionalReferenceSwitch& operator=(const O& other) { reset(); + if (other) + { + Construct(other.get()); + } + return *this; } @@ -267,13 +289,15 @@ class Optional final : public OptionalReferenceSwitch<std::is_reference<T>::valu public: using BaseSwitch = OptionalReferenceSwitch<std::is_reference<T>::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<T>& other) : BaseSwitch{other} {} + template <typename O, + typename = std::enable_if_t<CheckBoostOptionalSignature<O>::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<std::string>(), false, ""); BoostCompatibilityTester(armnn::Optional<std::string>("Hello World"), true, "Hello World"); + // verify boost signature selector + BOOST_TEST(armnn::CheckBoostOptionalSignature<boost::optional<std::string>>::Result() == true); + BOOST_TEST(armnn::CheckBoostOptionalSignature<armnn::Optional<std::string>>::Result() == false); + // the real thing is to see that we can pass a boost::optional in place // of an ArmNN Optional boost::optional<std::string> empty; |