mcqc icon indicating copy to clipboard operation
mcqc copied to clipboard

Forward declaration of structs and variants

Open elefthei opened this issue 5 years ago • 0 comments

Cyclical recursive references of constructors is a problem. Hopefully, forward declaration in C++ works, so the following for a list is better

template<class T>
struct Coq_nil;
template<class T>
struct Coq_cons;
template<class T>
using list = std::variant<Coq_nil<T>, Coq_cons<T>>;

template<class T>
struct Coq_nil {};

template<class T>
struct Coq_cons {
  T a;
  std::shared_ptr<list<T>> b;
  Coq_cons(T a, std::shared_ptr<list<T>> b) {
    this->a = a;
    this->b = b;
  };
};

elefthei avatar Jan 18 '19 04:01 elefthei