FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
November 01, 2005

An Efficient Variant Type

(Page 7 of 7)

November, 2005: An Efficient Variant Type

Listing 6


  template<typename T>
  struct optimize
  {
    enum
    {
        T_size_    = sizeof(T)
      , base_size_  = sizeof(object_holder)
      , size_ok_    = (T_size_ <= base_size_)
      , value      = size_ok_
    };
  };

  template<typename T>
  struct table
  {
    enum { optimized = sizeof(T) <= sizeof(object_holder) };

    static fxn_ptr_table* get()
    {
      static fxn_ptr_table static_table = {
        &fxns<optimized>::template impl<T>::type
      , &fxns<optimized>::template impl<T>::destructor
      , &fxns<optimized>::template impl<T>::static_delete
      , &fxns<optimized>::template impl<T>::clone
      , &fxns<optimized>::template impl<T>::assign
      , &fxns<optimized>::template impl<T>::is_optimized
      , &fxns<optimized>::template impl<T>::swap
      };
      return &static_table;
    }
  };

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK