14#ifndef RANGES_V3_UTILITY_ANY_HPP
15#define RANGES_V3_UTILITY_ANY_HPP
29#include <range/v3/detail/prologue.hpp>
32RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
38 virtual const char * what()
const noexcept override
40 return "bad any_cast";
44 struct RANGES_DEPRECATED(
45 "ranges::
any will be going away
in the not-too-distant future. "
46 "We suggest you use std::any or boost::any
instead (or simply steal "
47 "this header and maintain it yourself).")
any;
50 meta::if_c<std::is_reference<T>() || copyable<T>, T>
any_cast(any &);
53 meta::if_c<std::is_reference<T>() || copyable<T>, T>
any_cast(any const &);
56 meta::if_c<std::is_reference<T>() || copyable<T>, T>
any_cast(any &&);
62 T const *
any_cast(any const *) noexcept;
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
172#if RANGES_BROKEN_CPO_LOOKUP
175 inline void swap(
any & x,
any & y)
noexcept
184 meta::if_c<std::is_reference<T>() || copyable<T>, T>
any_cast(
any & x)
186 if(x.type() !=
typeid(detail::decay_t<T>))
188 return static_cast<any::impl<detail::decay_t<T>
> *>(x.ptr_.get())->get();
193 meta::if_c<std::is_reference<T>() || copyable<T>, T>
any_cast(
any const & x)
195 if(x.type() !=
typeid(detail::decay_t<T>))
197 return static_cast<any::impl<detail::decay_t<T>
> const *>(x.ptr_.get())->get();
202 meta::if_c<std::is_reference<T>() || copyable<T>, T>
any_cast(
any && x)
204 if(x.type() !=
typeid(detail::decay_t<T>))
206 return static_cast<any::impl<detail::decay_t<T>
> *>(x.ptr_.get())->get();
214 if(any::impl<T> * q =
dynamic_cast<any::impl<T> *
>(p->ptr_.get()))
224 if(any::impl<T>
const * q =
dynamic_cast<any::impl<T>
const *
>(p->ptr_.get()))
232#include <range/v3/detail/epilogue.hpp>
meta::if_c< std::is_reference< T >()||copyable< T >, T > any_cast(any &)
Definition: any.hpp:184
I P I S j decltype(detail::insert_impl(static_cast< Cont && >(cont), static_cast< P && >(p), static_cast< I && >(i), static_cast< S && >(j), meta::bool_< random_access_reservable< Cont > &&//sized_sentinel_for< S, I > >{})) template(typename Cont, typename I, typename Rng)(AND input_iterator< I > AND range< Rng >) auto insert(Cont &&cont
function template any_of
Definition: insert.hpp:188
bool_< 0==size< L >::type::value > empty
An Boolean integral constant wrapper around true if L is an empty type list; false,...
Definition: meta.hpp:2231
not_< empty< find< L, T > > > in
A Boolean integral constant wrapper around true if there is at least one occurrence of T in L.
Definition: meta.hpp:3081
Definition: pipeable.hpp:76