项目作者: HunMaDog

项目描述 :
PolyH - Polymorphic Helpers
高级语言: C++
项目地址: git://github.com/HunMaDog/PolyH.git
创建时间: 2020-08-23T12:32:29Z
项目社区:https://github.com/HunMaDog/PolyH

开源协议:MIT License

下载


PolyH

PolyH - Polymorphic Helpers

VirtualBase

Curiously recurring template pattern solution with supporting multilevel inheritance and without suffering from diamond problem.

  1. #include "detail/polyh/crtp_macro.hpp"
  2. #include "detail/polyh/virtual_base.hpp"
  3. #include <iostream>
  4. constexpr int forty_and_two{42};
  5. template<typename Derived>
  6. class Question : public marklar::detail::polyh::VirtualBase<Derived, Question> {
  7. public:
  8. void print_answer() const noexcept
  9. {
  10. std::cout << CRTP_UNDERLYING.answer() << " - The Answer to the Ultimate Question of Life, The Universe, and Everything.\n";
  11. }
  12. };
  13. class Answer : public Question<Answer> {
  14. CRTP_FRIEND(Question<Answer>)
  15. protected:
  16. constexpr int answer() const noexcept
  17. {
  18. return forty_and_two;
  19. }
  20. };
  21. int main()
  22. {
  23. Answer answare;
  24. answare.print_answer();
  25. return 0;
  26. }

VirtualAssign

Work in progress

VirtualCompare

Work in progress