dblaikie added a comment.

Perhaps all these clone implementations could be provided via mixin instead?

  struct base {
    virtual std::shared_ptr<base> Clone() = 0;
    ...
  };
  template<typename Derived, typename IntermediateBase = base>
  struct base_clone_helper : IntermediateBase {
    static_assert(std::is_base_of<base, IntermediateBase>::value);
    std::shared_ptr<base> Clone() const override {
      return std::make_shared<Derived>(static_cast<const Derived&>(*this*));
    }
  };
  struct some_immediate_derivation final : 
base_clone_helper<some_immediate_derivation> {
  };
  struct some_intermediate_helper : base {
    ...
  };
  struct some_concrete_derivation final : 
base_clone_helper<some_concrete_derivation, some_intermediate_helper> {
  };

Requiring that all such types be copy constructible (I guess the template 
helper could also provide an rvalue overload of Clone if there's a need to have 
move cloning, though that seems unlikely to be needed/useful)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96817/new/

https://reviews.llvm.org/D96817

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to