From 294c254f29317e9ddffbb904ea273a72b29432ac Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 20 Jun 2009 23:17:22 +0200 Subject: [PATCH] Fix instantiation of Tuple datastructs --- src/lib/meta/tuple.hpp | 27 +++++++++++++++++++++++++++ src/lib/util.hpp | 10 ++++++++++ src/proc/control/command-closure.hpp | 13 ++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/lib/meta/tuple.hpp b/src/lib/meta/tuple.hpp index ec8f5dd72..4cb0a49d8 100644 --- a/src/lib/meta/tuple.hpp +++ b/src/lib/meta/tuple.hpp @@ -294,6 +294,33 @@ namespace typelist{ }; + template<> + struct Tuple > + : Tuple + { + enum { SIZE = 0 }; + typedef Tuple TupleNull; + + Tuple ( NullType =NullType() + , NullType =NullType() + , NullType =NullType() + , NullType =NullType() + , NullType =NullType() + , NullType =NullType() + , NullType =NullType() + , NullType =NullType() + , NullType =NullType() + ) + { } ///< end recursion of chained ctor calls + + + template struct ShiftedTuple { typedef TupleNull Type; }; + + template TupleNull& getShifted () { return static_cast (*this); } + template NullType& getAt () { return getHead(); } + }; + + namespace tuple { // some convenience access functions diff --git a/src/lib/util.hpp b/src/lib/util.hpp index a835fc443..40845283f 100644 --- a/src/lib/util.hpp +++ b/src/lib/util.hpp @@ -190,6 +190,16 @@ namespace util { } + /** shortcut to save some typing when having to define + * const and non-const variants of member functions + */ + template + OBJ* + unConst (const OBJ* o) + { + return const_cast (o); + } + /** produce an identifier based on the given string. diff --git a/src/proc/control/command-closure.hpp b/src/proc/control/command-closure.hpp index 56085e74d..56efd3302 100644 --- a/src/proc/control/command-closure.hpp +++ b/src/proc/control/command-closure.hpp @@ -41,6 +41,7 @@ #include "lib/meta/function-closure.hpp" #include "lib/meta/function-erasure.hpp" #include "lib/meta/tuple.hpp" +#include "lib/util.hpp" #include #include @@ -59,6 +60,7 @@ namespace control { // using lumiera::Symbol; // using std::tr1::shared_ptr; + using util::unConst; using std::string; using std::ostream; using std::tr1::function; @@ -110,7 +112,8 @@ namespace control { class ParamAccessor : public BASE { - TY& element() { return BASE::template getAt(); } + TY & element() { return BASE::template getAt(); } + TY const& element() const { return unConst(this)->template getAt(); } public: @@ -123,7 +126,7 @@ namespace control { string dump (string const& prefix = "(") const { - return BASE::dump (prefix+element()); + return BASE::dump (prefix+element()+","); } @@ -145,7 +148,11 @@ namespace control { string dump (string const& prefix) const { - return prefix+")"; + if (1 < prefix.length()) + // remove trailing comma... + return prefix.substr (0, prefix.length()-1) +")"; + else + return prefix+")"; } };