diff options
author | James Ward <james.ward@arm.com> | 2020-09-25 11:43:21 +0100 |
---|---|---|
committer | James Ward <james.ward@arm.com> | 2020-09-30 08:41:31 +0000 |
commit | 22a4e1539aca7d39d7abc932f0a4d0b27beedf80 (patch) | |
tree | 95152943571413af5a3b550ac391bb17f258feef /third-party/mapbox/recursive_wrapper.hpp | |
parent | ba3ef18cb6117c49fcdbf177dce5991d6d679cbc (diff) | |
download | armnn-22a4e1539aca7d39d7abc932f0a4d0b27beedf80.tar.gz |
IVGCVSW-4519 Remove Boost Variant and apply_visitor variant
* add mapbox/variant third party package
Signed-off-by: James Ward <james.ward@arm.com>
Change-Id: I181302780edd9dace40f158a11327316a12ce69a
Diffstat (limited to 'third-party/mapbox/recursive_wrapper.hpp')
-rw-r--r-- | third-party/mapbox/recursive_wrapper.hpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/third-party/mapbox/recursive_wrapper.hpp b/third-party/mapbox/recursive_wrapper.hpp new file mode 100644 index 0000000000..4ffcbd7c93 --- /dev/null +++ b/third-party/mapbox/recursive_wrapper.hpp @@ -0,0 +1,122 @@ +#ifndef MAPBOX_UTIL_RECURSIVE_WRAPPER_HPP +#define MAPBOX_UTIL_RECURSIVE_WRAPPER_HPP + +// Based on variant/recursive_wrapper.hpp from boost. +// +// Original license: +// +// Copyright (c) 2002-2003 +// Eric Friedman, Itay Maman +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <cassert> +#include <utility> + +namespace mapbox { +namespace util { + +template <typename T> +class recursive_wrapper +{ + + T* p_; + + void assign(T const& rhs) + { + this->get() = rhs; + } + +public: + using type = T; + + /** + * Default constructor default initializes the internally stored value. + * For POD types this means nothing is done and the storage is + * uninitialized. + * + * @throws std::bad_alloc if there is insufficient memory for an object + * of type T. + * @throws any exception thrown by the default constructur of T. + */ + recursive_wrapper() + : p_(new T){} + + ~recursive_wrapper() noexcept { delete p_; } + + recursive_wrapper(recursive_wrapper const& operand) + : p_(new T(operand.get())) {} + + recursive_wrapper(T const& operand) + : p_(new T(operand)) {} + + recursive_wrapper(recursive_wrapper&& operand) + : p_(new T(std::move(operand.get()))) {} + + recursive_wrapper(T&& operand) + : p_(new T(std::move(operand))) {} + + inline recursive_wrapper& operator=(recursive_wrapper const& rhs) + { + assign(rhs.get()); + return *this; + } + + inline recursive_wrapper& operator=(T const& rhs) + { + assign(rhs); + return *this; + } + + inline void swap(recursive_wrapper& operand) noexcept + { + T* temp = operand.p_; + operand.p_ = p_; + p_ = temp; + } + + recursive_wrapper& operator=(recursive_wrapper&& rhs) noexcept + { + swap(rhs); + return *this; + } + + recursive_wrapper& operator=(T&& rhs) + { + get() = std::move(rhs); + return *this; + } + + T& get() + { + assert(p_); + return *get_pointer(); + } + + T const& get() const + { + assert(p_); + return *get_pointer(); + } + + T* get_pointer() { return p_; } + + const T* get_pointer() const { return p_; } + + operator T const&() const { return this->get(); } + + operator T&() { return this->get(); } + +}; // class recursive_wrapper + +template <typename T> +inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) noexcept +{ + lhs.swap(rhs); +} +} // namespace util +} // namespace mapbox + +#endif // MAPBOX_UTIL_RECURSIVE_WRAPPER_HPP |