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