0

Given the following Dart code:

class B {}
mixin M0 on B {}
mixin M1 on B {}
class C extends B with M0, M1 {}

Is the following C++ code kind of what is going on under the hood of Dart mixins?

class B {};

template<class T>
class M0 : public T {
public: static_assert(std::is_base_of_v<B, T>);
};

template<class T>
class M1 : public T {
public: static_assert(std::is_base_of_v<B, T>);
};

class C : public M1<M0<B>> {};
jamesdlin
  • 81,374
  • 13
  • 159
  • 204
Oleksa
  • 635
  • 5
  • 15
  • Currently answering this requires both Dart and C++. Can you explain how those mixins work for those who don't know Dart? In particular, what those mixins can access? Only the members of `B`? Or of `C` as well? – HolyBlackCat Jul 31 '21 at 07:46
  • 1
    @HolyBlackCat I believe that's OP's question too: "How do mixins exactly work? Please explain in terms of C++ concepts that I know". – Aykhan Hagverdili Jul 31 '21 at 07:54
  • @HolyBlackCat, yes, answering it requires some knowledge of both. I assume there is people with such knowledge. They can access only the members of `B`. – Oleksa Jul 31 '21 at 07:56
  • Yes, I think that C++ code is equivalent. See [lrn's explanation of Dart mixins](https://stackoverflow.com/a/45903671/). – jamesdlin Jul 31 '21 at 08:50

0 Answers0