From: Joel R. <jo...@gm...> - 2009-02-26 17:07:18
|
> I started with this OCaml recursive type: type ty = | TyAny | TyInt | TyFloat | TyBool | TyStr | TyColor | TyStyle | TyList of ty | TyArray of ty | TySeries of ty | TyInput of ty | TyRef of ty | TyUnit | TyPrintDest | TyPrintExpr and ended up with this MUCH larger of C++ struct AnyType {}; struct IntType {}; struct FloatType {}; struct BoolType {}; struct StrType {}; struct ColorType {}; struct StyleType {}; struct UnitType {}; struct PrintDestType {}; struct PrintExprType {}; struct ListType; struct ArrayType; struct SeriesType; struct InputType; struct RefType; struct TypeAST { typedef boost::variant< nil , boost::recursive_wrapper<TypeAST> , boost::recursive_wrapper<ListType> , boost::recursive_wrapper<ArrayType> , boost::recursive_wrapper<SeriesType> , boost::recursive_wrapper<InputType> , boost::recursive_wrapper<RefType> , AnyType , IntType , FloatType , BoolType , StrType , ColorType , StyleType , UnitType , PrintDestType , PrintExprType > type; TypeAST() : ty(nil()) {} template <typename T> TypeAST(T const& ty) : ty(ty) {} type ty; }; struct TypeOf { TypeOf( TypeAST const& ty ): ty(ty) {} TypeAST ty; }; struct ListType: public TypeOf {}; struct ArrayType: public TypeOf {}; struct SeriesType: public TypeOf {}; struct InputType: public TypeOf {}; struct RefType: public TypeOf {}; --- http://tinyco.de Mac Trading Apps |