diff --git a/docs.in/reference/method.cpp b/docs.in/reference/method.cpp index f3d2c453..bc34f42e 100644 --- a/docs.in/reference/method.cpp +++ b/docs.in/reference/method.cpp @@ -181,7 +181,10 @@ make sense, see the example below. #include #include -struct Animal { virtual ~Animal() {} }; +struct Animal { + virtual ~Animal() { + } +}; struct Cat : Animal {}; struct Dog : Animal {}; struct Bulldog : Dog {}; @@ -194,33 +197,43 @@ YOMM2_REGISTER(yomm2::use_classes); struct kick_methods; using kick = yomm2::method), std::string>; -std::string kick_cat(Cat& dog) { return "hiss"; } +std::string kick_cat(Cat& dog) { + return "hiss"; +} YOMM2_REGISTER(kick::override_fn); -std::string kick_dog(Dog& dog) { return "bark"; } +std::string kick_dog(Dog& dog) { + return "bark"; +} YOMM2_REGISTER(kick::override_fn); -struct kick_bulldog : kick::with_next { - static std::string fn(Bulldog& dog) { return next(dog) + " and bite"; } +struct kick_bulldog { + static std::string fn(Bulldog& dog) { + return kick::next(dog) + " and bite"; + } }; YOMM2_REGISTER(kick::override); struct YOMM2_METHOD_NAME(pet); // use obfuscated name -using pet = yomm2::method), std::string>; +using pet = + yomm2::method), std::string>; -std::string pet_cat(Cat& dog) { return "purr"; } +std::string pet_cat(Cat& dog) { + return "purr"; +} YOMM2_REGISTER(pet::override_fn); -std::string pet_dog(Dog& dog) { return "wag tail"; } +std::string pet_dog(Dog& dog) { + return "wag tail"; +} YOMM2_REGISTER(pet::override_fn); BOOST_AUTO_TEST_CASE(ref_method_example) { yomm2::initialize(); - std::unique_ptr - felix = std::make_unique(), - snoopy = std::make_unique(), - hector = std::make_unique(); + std::unique_ptr felix = std::make_unique(), + snoopy = std::make_unique(), + hector = std::make_unique(); BOOST_TEST(kick::fn(*felix) == "hiss"); BOOST_TEST(kick::fn(*snoopy) == "bark"); diff --git a/docs.in/tutorials/api.cpp b/docs.in/tutorials/api.cpp index e3e1cf22..6f337128 100644 --- a/docs.in/tutorials/api.cpp +++ b/docs.in/tutorials/api.cpp @@ -127,13 +127,11 @@ kick::override_fn add_kick_dog; // > // code< -kick::next_type kick_bulldog_next; - std::string kick_bulldog(Bulldog& dog) { - return kick_bulldog_next(dog) + " and bite back"; + return kick::next(dog) + " and bite back"; } -kick::override_fn add_kick_bulldog(&kick_bulldog_next); +kick::override_fn add_kick_bulldog; // > // md< @@ -281,9 +279,9 @@ YOMM2_REGISTER(kick::override); // > // code< -struct kick_bulldog : kick::with_next { +struct kick_bulldog { static std::string fn(Bulldog& dog) { - return next(dog) + " and bite back"; + return kick::next(dog) + " and bite back"; } }; diff --git a/include/yorel/yomm2/core.hpp b/include/yorel/yomm2/core.hpp index 895fbf96..b7b16c5a 100644 --- a/include/yorel/yomm2/core.hpp +++ b/include/yorel/yomm2/core.hpp @@ -535,13 +535,6 @@ using spec_polymorphic_types = boost::mp11::mp_remove< MethodParameters, OverriderParameters>, void>; -template -struct has_next : std::false_type {}; - -template -struct has_next> - : std::true_type {}; - template struct static_offsets; @@ -637,11 +630,6 @@ class method : public detail::method_info { auto operator()(detail::remove_virtual... args) const -> Return; - template - struct with_next { - static next_type next; - }; - template static FunctionPointer next; @@ -669,7 +657,6 @@ class method : public detail::method_info { template struct override_fn_aux : override_fn_impl { - using override_fn_impl::override_fn_impl; }; template< @@ -695,27 +682,9 @@ class method : public detail::method_info { std::tuple...> fns; }; - private: - template - struct override_aux; - template - struct override_aux : override_fn { - override_aux() : override_fn(nullptr) { - } - }; - - template - struct override_aux : override_fn { - override_aux() : override_fn(&Container::next) { - } - }; - - public: - template - struct override - : override_aux::value> { - using type = override; // make it a meta-function + struct override : override_fn { + using type = override; }; }; @@ -723,11 +692,6 @@ template method method::fn; -template -template -typename method::next_type - method::with_next::next; - template template typename method::FunctionPointer diff --git a/include/yorel/yomm2/macros.hpp b/include/yorel/yomm2/macros.hpp index 180f4ac4..a1b6e06c 100644 --- a/include/yorel/yomm2/macros.hpp +++ b/include/yorel/yomm2/macros.hpp @@ -57,16 +57,20 @@ template<> \ struct OVERRIDERS { \ YOREL_YOMM2_DETAIL_LOCATE_METHOD(NAME, ARGS); \ - static method_type::next_type next; \ static auto fn ARGS->YOREL_YOMM2_DETAIL_RETURN_TYPE(__VA_ARGS__); \ + static auto has_next() { \ + return method_type::next != nullptr; \ + } \ + template \ + static decltype(auto) next(Args&&... args) { \ + BOOST_ASSERT(has_next()); \ + return method_type::next(std::forward(args)...); \ + } \ }; \ - INLINE OVERRIDERS::method_type::next_type \ - OVERRIDERS::next; \ INLINE YOMM2_REGISTER( \ OVERRIDERS:: \ - method_type::override>); \ + method_type::override_fn::fn>); \ INLINE auto \ OVERRIDERS::fn ARGS \ ->boost::mp11::mp_back> diff --git a/tests/test_core.cpp b/tests/test_core.cpp index ef7a5462..3ae78e0a 100644 --- a/tests/test_core.cpp +++ b/tests/test_core.cpp @@ -217,22 +217,6 @@ static_assert( } // namespace test_use_classes -namespace test_has_next { - -struct with_next { - static int next; -}; - -static_assert(has_next::value); - -struct sans_next { - static int next; -}; - -static_assert(has_next::value); - -} - namespace facets { using namespace policies;