[Lldb-commits] [PATCH] D96817: Fix deep copying for OptionValue classes

David Blaikie via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 16 16:53:49 PST 2021


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



More information about the lldb-commits mailing list