1 #ifndef OPENTRACING_UTIL_RECURSIVE_WRAPPER_HPP
2 #define OPENTRACING_UTIL_RECURSIVE_WRAPPER_HPP
4 // Based on variant/recursive_wrapper.hpp from boost.
8 // Copyright (c) 2002-2003
9 // Eric Friedman, Itay Maman
11 // Distributed under the Boost Software License, Version 1.0. (See
12 // accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
17 #include <opentracing/version.h>
19 namespace opentracing {
20 BEGIN_OPENTRACING_ABI_NAMESPACE
24 class recursive_wrapper
29 void assign(T const& rhs)
38 * Default constructor default initializes the internally stored value.
39 * For POD types this means nothing is done and the storage is
42 * @throws std::bad_alloc if there is insufficient memory for an object
44 * @throws any exception thrown by the default constructur of T.
49 ~recursive_wrapper() noexcept { delete p_; }
51 recursive_wrapper(recursive_wrapper const& operand)
52 : p_(new T(operand.get())) {}
54 recursive_wrapper(T const& operand)
55 : p_(new T(operand)) {}
57 recursive_wrapper(recursive_wrapper&& operand)
58 : p_(new T(std::move(operand.get()))) {}
60 recursive_wrapper(T&& operand)
61 : p_(new T(std::move(operand))) {}
63 inline recursive_wrapper& operator=(recursive_wrapper const& rhs)
69 inline recursive_wrapper& operator=(T const& rhs)
75 inline void swap(recursive_wrapper& operand) noexcept
82 recursive_wrapper& operator=(recursive_wrapper&& rhs) noexcept
88 recursive_wrapper& operator=(T&& rhs)
90 get() = std::move(rhs);
97 return *get_pointer();
103 return *get_pointer();
106 T* get_pointer() { return p_; }
108 const T* get_pointer() const { return p_; }
110 operator T const&() const { return this->get(); }
112 operator T&() { return this->get(); }
114 }; // class recursive_wrapper
116 template <typename T>
117 inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) noexcept
122 END_OPENTRACING_ABI_NAMESPACE
123 } // namespace opentracing
125 #endif // OPENTRACING_UTIL_RECURSIVE_WRAPPER_HPP