Hacker News new | ask | show | jobs
by otabdeveloper4 641 days ago
Store where?

C++ templates are a lambda calculus, there's no notion of memory cells or state.

1 comments

In a struct! Pseudo code for extracting the types from subclasses and calling a multimethod on them:

  template <typename Result, typename Head, typename ...Tail>
  struct Foo : Visitor {
    Result res;
    UntypedList lst; // This does not exist!
    Tail... tail;    // This is not possible!
    Foo(UntypedList l; Head hd, Tail... tl) : lst(l), tail(tl) {
      hd->accept(*this);
    }
    void visit(float *f) {
      res = Foo<Result, Tail...>(append(lst, f), tail)::res; }
    }
  };
 
  // Base case that calls the multimethod omitted.
There are two issues here: You can't store the parameter pack in Foo() which is later required by the continuation in visit(). And you would have to use tuples and tuple_cat() instead of UntypedList.

Why can the compiler not infer the types in such an UntypedList? Why is there no car/cdr for tuples?

Not sure what Untyped list is or supposed to do in the above. In fact I'm not sure what the code above is trying to do at all.

If you want a cons-based tuple, boost::tuple will work just fine (or you can implement your own, it is not hard). std::tuple is not (visibly) cons based.