20 class binary_extension {
24 constexpr binary_extension() {}
25 constexpr binary_extension(
const T& ext )
28 ::new (&_data) T(ext);
30 constexpr binary_extension( T&& ext )
33 ::new (&_data) T(std::move(ext));
36 template <
typename... Args>
37 constexpr binary_extension( std::in_place_t, Args&&... args )
40 ::new (&_data) T(std::forward<Args>(args)...);
43 constexpr binary_extension(
const binary_extension& other )
44 :_has_value(other._has_value)
46 if( other._has_value ) ::new (&_data) T( *other );
49 constexpr binary_extension( binary_extension&& other )
50 :_has_value(other._has_value)
52 if( other._has_value ) {
53 ::new (&_data) T( *std::move(other) );
54 other._has_value =
false;
59 ~binary_extension() { reset(); }
62 constexpr binary_extension& operator = (
const binary_extension& other) {
66 if (other.has_value()) {
67 ::new (&_data) T(*other);
74 constexpr binary_extension& operator = (binary_extension&& other) {
78 if (other.has_value()) {
79 ::new (&_data) T(*other);
81 other._has_value =
false;
86 constexpr explicit operator bool()
const {
return _has_value; }
88 constexpr bool has_value()
const {
return _has_value; }
91 constexpr T& value()& {
93 check(
false,
"cannot get value of empty binary_extension");
101 constexpr const T& value()const & {
103 check(
false,
"cannot get value of empty binary_extension");
111 template <
typename U>
112 constexpr auto value_or( U&& def ) -> std::enable_if_t<std::is_convertible<U, T>::value, T&>& {
117 constexpr T&& value_or()&& {
119 return std::move(T());
121 return std::move(_get());
123 constexpr const T&& value_or()const&& {
125 return std::move(T());
127 return std::move(_get());
129 constexpr T value_or()& {
134 constexpr T value_or()const& {
140 constexpr T* operator->() {
143 constexpr const T* operator->()
const {
147 constexpr T& operator*()& {
150 constexpr const T& operator*()const& {
153 constexpr const T&& operator*()const&& {
154 return std::move(_get());
156 constexpr T&& operator*()&& {
157 return std::move(_get());
160 template<
typename ...Args>
161 T& emplace(Args&& ... args)& {
166 ::new (&_data) T( std::forward<Args>(args)... );
174 _get().~value_type();
182 bool _has_value =
false;
183 typename std::aligned_storage<
sizeof(T),
alignof(T)>::type _data;
185 constexpr T& _get() {
186 return *
reinterpret_cast<T*
>(&_data);
189 constexpr const T& _get()
const {
190 return *
reinterpret_cast<const T*
>(&_data);
206 template<
typename DataStream,
typename T>
207 inline DataStream&
operator<<(DataStream& ds,
const eosio::binary_extension<T>& be) {
222 template<
typename DataStream,
typename T>
223 inline DataStream&
operator>>(DataStream& ds, eosio::binary_extension<T>& be) {
224 if( ds.remaining() ) {