23 #ifndef STDEXT_PACKEDANY_H
24 #define STDEXT_PACKEDANY_H
28 #include <type_traits>
38 (sizeof(T) <= sizeof(void*) && std::is_trivial<T>::value)> {};
44 virtual ~placeholder() { }
45 virtual const std::type_info& type() const = 0;
46 virtual placeholder* clone() const = 0;
50 struct holder : public placeholder {
51 holder(const T& value) : held(value) { }
52 const std::type_info& type() const { return typeid(T); }
53 placeholder* clone() const { return new holder(held); }
56 holder& operator=(const holder &);
63 content(nullptr), scalar(false) { }
64 packed_any(const packed_any& other) :
65 content(!other.scalar && other.content ? other.content->clone() : other.content),
66 scalar(other.scalar) { }
69 content(reinterpret_cast<
placeholder*>(static_cast<
std::size_t>(value))), scalar(true) { }
72 content(new
holder<T>(value)), scalar(false) { }
74 {
if(!scalar && content)
delete content; }
81 bool empty()
const {
return !scalar && !content; }
82 template<
typename T> T
cast()
const;
83 const std::type_info&
type()
const {
85 return content ? content->type() :
typeid(void);
87 return typeid(std::size_t);
92 typename std::enable_if<can_pack_in_any<T>::value, T>::type
104 typename std::enable_if<!can_pack_in_any<T>::value, T>::type
106 assert(operand.
type() ==
typeid(T));