68 friend meta::if_c<std::is_reference<T>() || (bool)copyable<T>, T>
any_cast(
any &);
71 friend meta::if_c<std::is_reference<T>() || (bool)copyable<T>, T>
any_cast(
75 friend meta::if_c<std::is_reference<T>() || (bool)copyable<T>, T>
any_cast(
88 virtual interface * clone()
const = 0;
89 virtual std::type_info
const & type()
const noexcept = 0;
93 struct impl final : interface
107 T
const & get()
const
111 impl * clone()
const override
113 return new impl{obj};
115 std::type_info
const & type()
const noexcept override
121 std::unique_ptr<interface> ptr_;
124 any()
noexcept =
default;
125 template(
typename TRef,
typename T = detail::decay_t<TRef>)(
126 requires copyable<T> AND (!same_as<T, any>))
128 : ptr_(
new impl<T>(
static_cast<TRef &&
>(t)))
130 any(
any &&)
noexcept =
default;
132 : ptr_{that.ptr_ ? that.ptr_->clone() :
nullptr}
134 any & operator=(
any &&)
noexcept =
default;
135 any & operator=(
any const & that)
137 ptr_.reset(that.ptr_ ? that.ptr_->clone() :
nullptr);
140 template(
typename TRef,
typename T = detail::decay_t<TRef>)(
141 requires copyable<T> AND (!same_as<T, any>))
142 any &
operator=(TRef && t)
144 any{
static_cast<TRef &&
>(t)}.swap(*
this);
147 void clear()
noexcept
151 bool empty()
const noexcept
155 std::type_info
const & type()
const noexcept
157 return ptr_ ? ptr_->type() :
typeid(void);
159 void swap(
any & that)
noexcept
161 ptr_.swap(that.ptr_);
164#if !RANGES_BROKEN_CPO_LOOKUP
165 friend void swap(
any & x,
any & y)
noexcept