diff --git a/docs.in/README.md b/docs.in/README.md index 313710cd..0a2f293b 100644 --- a/docs.in/README.md +++ b/docs.in/README.md @@ -51,8 +51,9 @@ virtual parameters, is also aliases in the global namespace. The library can also be used through the _core interface_, which is almost entirely free of macros. The primary use of this interface is to support templatized classes, methods and definitions - something that macros are -incapable of. See [the templates tutorial](/tutorials/templates_tutorial.html) for -more details and examples. +incapable of. See [the templates +tutorial](/yomm2/tutorials/templates_tutorial.html) for more details and +examples. ## Exceptions diff --git a/docs/README.md b/docs/README.md index 313919ec..e79eb6e7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -52,8 +52,9 @@ virtual parameters, is also aliases in the global namespace. The library can also be used through the _core interface_, which is almost entirely free of macros. The primary use of this interface is to support templatized classes, methods and definitions - something that macros are -incapable of. See [the templates tutorial](/tutorials/templates_tutorial.html) for -more details and examples. +incapable of. See [the templates +tutorial](/yomm2/tutorials/templates_tutorial.html) for more details and +examples. ## Exceptions diff --git a/docs/tutorials/api.md b/docs/tutorials/api.md index de3ceac8..362f436e 100644 --- a/docs/tutorials/api.md +++ b/docs/tutorials/api.md @@ -1,4 +1,4 @@ -# + # Using YOMM2 without macros @@ -27,7 +27,7 @@ class Bulldog : public Dog {}; use_classes use_animal_classes; ``` -# + The new `use_classes` template takes any number of @@ -41,7 +41,7 @@ invocations of `register_class`. struct kick_key; using kick_method = method)>; ``` -# + A YOMM2 method is implemented as a singleton of an instance of the `method` @@ -56,7 +56,7 @@ the same signature. Consider a more animal-friendly method: struct feed_key; using feed_method = method)>; ``` -# + In the absence of the first parameter, `kick` and `feed` would be the same @@ -78,7 +78,7 @@ std::string kick_dog(Dog& dog) { kick_method::add_function add_kick_dog; ``` -# + Note that the name of the function serving as a method definition must be @@ -100,7 +100,7 @@ std::string kick_bulldog(Bulldog& dog) { kick_method::add_function add_kick_bulldog(&kick_bulldog_next); ``` -# + We can now call the method. The class contains a static function object named @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(test_synopsis_functions_no_macros) { BOOST_TEST(kick_method::fn(*hector) == "bark and bite back"); } ``` -# + ## A peek inside the two main YOMM2 macros @@ -162,7 +162,7 @@ In addition, the header provides These macros are defined by header file `yorel/yomm2/symbols.hpp`. -# + ## Trimming verbosity @@ -177,7 +177,7 @@ Let's rewrite the example, this time using the symbol-generation macros, and a helper. -# + (`Animal` classes same as before) @@ -195,7 +195,7 @@ struct YOMM2_SYMBOL(kick); using kick_method = method)>; ``` -# + `add_function` is a workhorse that is intended to be used directly only by @@ -216,7 +216,7 @@ struct kick_dog { YOMM2_STATIC(kick_method::add_definition); ``` -# + This may not seem like a huge improvement, until we need a `next` function. @@ -236,7 +236,7 @@ struct kick_bulldog : kick_method::next { YOMM2_STATIC(kick_method::add_definition); ``` -# + Do you have doubts about the value of definition containers? Here are two diff --git a/docs/tutorials/custom_rtti_tutorial.md b/docs/tutorials/custom_rtti_tutorial.md index 3445379b..a18faf3c 100644 --- a/docs/tutorials/custom_rtti_tutorial.md +++ b/docs/tutorials/custom_rtti_tutorial.md @@ -1,4 +1,4 @@ -# + # Using Custom RTTI @@ -73,7 +73,7 @@ struct std_rtti : rtti { template static void type_name(type_id type, Stream& stream) { - stream << reinterpret_cast(type)->name(); + stream << reinterpret_cast(type)[name](None)(); } static std::type_index type_index(type_id type) { @@ -146,7 +146,6 @@ struct Cat : virtual Animal { const char* Cat::static_type = "Cat"; ``` -# We need to write a `rtti` facet for this RTTI system. Note that, in this @@ -198,7 +197,6 @@ struct custom_rtti : policy::rtti { } }; ``` -# Now we need to create a policy which is the same as the default policy in every @@ -222,7 +220,6 @@ Thus we create the policy with: struct custom_policy : default_policy::rebind::replace< policy::rtti, custom_rtti> {}; ``` -# Finally, we must specify the new policy during class registration and method @@ -243,7 +240,6 @@ define_method(void, kick, (Cat & cat, std::ostream& os)) { os << cat.name << " hisses."; } ``` -# The `update` function operates on the default policy. We need to call the @@ -271,7 +267,6 @@ BOOST_AUTO_TEST_CASE(custom_rtti_demo) { } } ``` -# ## Taking advantage of custom RTTI specificities @@ -309,7 +304,6 @@ struct Cat : Animal { static constexpr size_t static_type = 3; }; ``` -# In this situation, we can save time on hashing. If a policy has a `type_hash` @@ -365,7 +359,6 @@ define_method(void, kick, (Cat & cat, std::ostream& os)) { os << cat.name << " hisses."; } ``` -# A call to `kick` now compiles to a shorter assembly code: @@ -421,7 +414,6 @@ struct Cat : Animal { size_t Cat::static_type = ++Animal::last_type_id; ``` -# This is potentially a problem, because YOMM2 itself uses static constructors to @@ -454,7 +446,6 @@ struct custom_rtti : policy::deferred_static_rtti { } }; ``` -# The only change is that the custom facet now inherits from diff --git a/docs/tutorials/templates_tutorial.md b/docs/tutorials/templates_tutorial.md index b8adcb08..3a3197a6 100644 --- a/docs/tutorials/templates_tutorial.md +++ b/docs/tutorials/templates_tutorial.md @@ -1,4 +1,4 @@ -# + # Abstract @@ -101,7 +101,7 @@ class handle { // etc }; ``` -# + # A `vector` library @@ -136,7 +136,7 @@ using vector = handle; vector ints(new concrete_vector{1, 2, 3}); vector reals(new concrete_vector{4., 5., 6.}); ``` -# + ## Operations on vectors. @@ -176,7 +176,7 @@ using comparison = method< virtual_, virtual_)>; ``` -# + For the user's convenience, we wrap the method call in an operator: @@ -195,7 +195,7 @@ inline bool operator==(const vector& a, const vector& b) { return comparison::fn(*a.get(), *b.get()); } ``` -# + Now we need to provide definitions for these methods. But which ones? @@ -256,7 +256,7 @@ template: template struct definition; ``` -# + Let's create partial specializations that defines addition, subtraction and @@ -301,7 +301,7 @@ struct definition { } }; ``` -# + Let's suppose that we want to perform those three operations for vectors of @@ -342,7 +342,7 @@ static_assert( > >); ``` -# + `use_definitions` takes a class template and a Cartesian product, and applies @@ -369,7 +369,7 @@ use_definitions< > > YOMM2_GENSYM; ``` -# + Everything is now in place. After calling `update` as usual, we can @@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(test_vectors) { } } ``` -# + ## Writing a user-friendly instantiation function @@ -427,7 +427,7 @@ using use_vector_library = std::tuple< > >; ``` -# + All the user of the library needs to do now is to create an instance (object) @@ -437,14 +437,14 @@ of `use_vector_library`, instantiated with the required types: ```c++ use_vector_library init_vectors; ``` -# + This example fulfills goals (1) and (2) assigned to library designers. In the following, more complex example, we will see how to fulfill goal (3) as well. -# + # A matrix library @@ -550,7 +550,7 @@ struct symmetric : any_symmetric { } }; ``` -# + The `concrete` virtual function is just a way of making the `any_` classes @@ -675,7 +675,7 @@ auto operator*(T a, const handle>& b) { return handle(new symmetric>(...)); } ``` -# + Let's exercise the operators with a test case: @@ -733,7 +733,7 @@ BOOST_AUTO_TEST_CASE(test_static_operations) { } } ``` -# + Note that a `symmetric` matrix cannot be converted to a `square` matrix. This @@ -765,7 +765,7 @@ auto operator~(const handle>& m) { return transpose>::fn(*m.get()); } ``` -# + We must make sure that the new `operator~` is generated only if the deduced @@ -846,7 +846,7 @@ struct unary_definition< } }; ``` -# + 1. The default template argument evaluates to `std::true_type` if @@ -865,7 +865,7 @@ Let's create a few convenient aliases for `templates` lists: using abstract_matrix_templates = templates; using concrete_matrix_templates = templates; ``` -# + We will also need a list of all the templates - abstract and concrete. For @@ -876,7 +876,7 @@ that we can use `boost::mp11::mp_append`: using matrix_templates = boost::mp11::mp_append< abstract_matrix_templates, concrete_matrix_templates>; ``` -# + We can now use `product` to create all the combinations, and pass them to @@ -891,7 +891,7 @@ use_definitions< concrete_matrix_templates, types>> YOMM2_GENSYM; ``` -# + We must not forget to register all the matrix classes, for both numeric @@ -926,7 +926,7 @@ BOOST_AUTO_TEST_CASE(test_dynamic_transpose) { BOOST_TEST(sy.get() == tsy.get()); } ``` -# + ## Polymorphic Addition @@ -963,7 +963,7 @@ static_assert(std::is_same_v< // etc ``` -# + We can now declare the `add` method: @@ -988,7 +988,7 @@ auto operator+(const handle& a, const handle& b) { *a, *b); } ``` -# + Let's generate definitions for the `add` methods, and other binary methods @@ -1045,7 +1045,7 @@ struct enable_binary_definition< binary_result_type, A2>, binary_result_type, C2>>> {}; ``` -# + We can now implement `binary_defintion`: @@ -1070,7 +1070,7 @@ struct binary_definition< } }; ``` -# + ...and use it to generate definitions for polymorphic addition of matrices of @@ -1112,7 +1112,7 @@ BOOST_AUTO_TEST_CASE(test_dynamic_operations) { } } ``` -# + Now we need to create a mechanism that enable users to instantiate just the @@ -1134,7 +1134,7 @@ static_assert( std::is_same_v< template_of::abstract_type>::type, template_>); ``` -# + As for the methods, different method definitions need different Cartesian @@ -1176,7 +1176,7 @@ struct definition_traits : unary_definition_traits {}; template<> struct definition_traits : binary_definition_traits {}; ``` -# + We can now write `use_polymorphic_matrices` and its nested templates: