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
October 01, 2000

An Improved Variant Type Based on Member Templates

(Page 7 of 8)
October 2000/An Improved Variant Type Based on Member Templates/Listing 6

Listing 6: The class ArgumentList

#ifndef ARGLIST_H
#define ARGLIST_H

#include<vector>

#include"variant.h"

class ArgumentList
{
  public:

    // Ctor, Dtor, CopyCtor, and Assign ommited
    // because the defaults are apropriate.

    template<typename T> void push_back ( T Value )
      { _container.push_back ( variant_t ( Value ) ) ; }

    // NOTE: This returns a COPY of the value at pos idx.
    template<typename T> T operator [] ( size_t idx ) const
      { return _container [ idx ] ; }

    // This form returns a REFERENCE and not a COPY.
    template<typename T> const T & at ( size_t idx ) const
      { return _container [ idx ].get<T>() ; }

    bool   empty() const { return _container.empty(); }
    size_t size () const { return _container.size (); }

  private:
    std::vector<variant_t> _container ;
} ;

#endif


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



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK