@@ -26,38 +26,29 @@ public: any_t() noexcept {};
2626
2727 /* ─······································································─*/
2828
29- uint type_size () const noexcept { return any_sz.null ()?0 : *any_sz; }
30- ulong count () const noexcept { return any_ptr.count (); }
31- bool empty () const noexcept { return any_ptr.null (); }
32- bool has_value () const noexcept { return !any_ptr.null (); }
29+ ulong type_size () const noexcept { return empty () ?0 : any_ptr->size (); }
30+ ulong count () const noexcept { return any_ptr.count (); } /* --------*/
31+ bool empty () const noexcept { return any_ptr.null (); } /* --------*/
32+ bool has_value () const noexcept { return !any_ptr.null (); } /* --------*/
33+ void free () const noexcept { /* --*/ any_ptr.free (); } /* --------*/
3334
3435 /* ─······································································─*/
3536
36- void free () const noexcept { any_ptr.free (); }
37-
38- /* ─······································································─*/
39-
40- void operator =( const char * f ) noexcept { set ( string::to_string (f) ); }
41-
42- template < class T >
43- void operator =( const T& f ) noexcept { set ( f ); }
44-
4537 template < class T >
4638 T as () const { return get<T>(); }
4739
4840 template < class T >
49- void set ( const T& f ) noexcept {
50- any_sz = new uint (sizeof (T));
51- any_ptr = new any_impl<T>(f);
52- }
41+ void set ( const T& f ) noexcept { any_ptr = new any_impl<T>(f); }
5342
5443 template < class T >
55- T get () const {
56- char any [ sizeof (T)/sizeof (char ) ]; if ( !has_value () )
57- { throw except_t (" any_t is null" ); }
58- if ( *any_sz != sizeof (any)*sizeof (char ) )
59- { throw except_t (" any_t incompatible sizetype" ); }
60- any_ptr->get ((void *)&any); return *(T*)(any);
44+ T get () const { const ulong size = sizeof (T) / sizeof ( char );
45+
46+ if ( !has_value () ) /* ----*/ { throw except_t (" any_t is null" ); } /* ---------*/
47+ if ( type_size ()!=sizeof (T) ){ throw except_t (" any_t incompatible sizetype" ); }
48+
49+ char any [ size ]; any_ptr->get ((void *)&any);
50+ return *(T*)(any); /* ----------------------*/
51+
6152 }
6253
6354 /* ─······································································─*/
@@ -70,8 +61,9 @@ public: any_t() noexcept {};
7061 class any_base {
7162 public:
7263 virtual ~any_base () noexcept {}
73- virtual void get ( void * /* unused*/ ) const noexcept {}
74- virtual void set ( void * /* unused*/ ) noexcept {}
64+ virtual void get ( void * /* unused*/ ) const noexcept {}
65+ virtual void set ( void * /* unused*/ ) /* -*/ noexcept {}
66+ virtual ulong size () /* ------------*/ const noexcept = 0;
7567 };
7668
7769 /* ─······································································─*/
@@ -80,16 +72,16 @@ public: any_t() noexcept {};
8072 class any_impl : public any_base {
8173 public:
8274 any_impl ( const T& f ) noexcept : any( f ) {}
83- virtual void get ( void * argc ) const noexcept { memcpy ( argc, (void *)&any, sizeof (T) ); }
84- virtual void set ( void * argc ) noexcept { memcpy ( (void *)&any, argc, sizeof (T) ); }
75+ virtual ulong size () /* ------*/ const noexcept { return sizeof (T); } /* -----------------*/
76+ virtual void get ( void * argc ) const noexcept { memcpy ( argc, (void *)&any, sizeof (T) ); }
77+ virtual void set ( void * argc ) /* -*/ noexcept { memcpy ( (void *)&any, argc, sizeof (T) ); }
8578 private:
8679 T any;
8780 };
8881
8982 /* ─······································································─*/
9083
9184 ptr_t <any_base> any_ptr;
92- ptr_t <uint> any_sz;
9385
9486};}
9587
0 commit comments