5 #ifndef _libint2_include_libint2_any_h_ 6 #define _libint2_include_libint2_any_h_ 22 using StorageType =
typename std::decay<T>::type;
25 any(
const any& that) : handle_(that.clone()) {}
26 any(
any&& that) : handle_(std::move(that.handle_)) { }
27 template<
typename U>
any(U&& value)
28 : handle_(
new handle<StorageType<U>>(std::forward<U>(value)))
32 any& operator=(
const any& a)
35 std::swap(*
this, tmp);
41 any tmp(std::forward<U>(a));
42 std::swap(*
this, tmp);
47 std::swap(handle_, a.handle_);
51 operator bool()
const {
return bool(handle_); }
53 template<
class U>
bool is()
const 55 typedef StorageType<U> T;
56 auto derived =
dynamic_cast<handle<T>*
> (handle_.get());
64 typedef StorageType<U> T;
66 #if not defined(NDEBUG) 67 auto derived =
dynamic_cast<handle<T>*
> (handle_.get());
69 throw std::bad_cast();
71 auto derived =
static_cast<handle<T>*
> (handle_.get());
74 return derived->value;
79 const StorageType<U>&
as()
const 81 typedef StorageType<U> T;
83 #if not defined(NDEBUG) 84 auto derived =
dynamic_cast<handle<T>*
> (handle_.get());
86 throw std::bad_cast();
88 auto derived =
static_cast<handle<T>*
> (handle_.get());
91 return derived->value;
97 return as<StorageType<U>>();
104 virtual ~handle_base() {}
106 virtual handle_base* clone()
const = 0;
110 struct handle : handle_base
112 template<
typename U> handle(U&& value) : value(std::forward<U>(value)) { }
116 handle_base* clone()
const {
return new handle<T>(value); }
119 handle_base* clone()
const 122 return handle_->clone();
127 std::unique_ptr<handle_base> handle_;
132 #endif // header guard Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
emulates boost::any
Definition: any.h:17
const StorageType< U > & as() const
Definition: any.h:79
StorageType< U > & as()
Definition: any.h:62