Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Apr 8, 2024
1 parent 9568d4c commit 2edef6a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 56 deletions.
5 changes: 3 additions & 2 deletions docs.in/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 12 additions & 12 deletions docs/tutorials/api.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#



# Using YOMM2 without macros
Expand Down Expand Up @@ -27,7 +27,7 @@ class Bulldog : public Dog {};

use_classes<Animal, Dog, Bulldog> use_animal_classes;
```
#
The new `use_classes` template takes any number of
Expand All @@ -41,7 +41,7 @@ invocations of `register_class`.
struct kick_key;
using kick_method = method<kick_key, std::string(virtual_<Animal&>)>;
```
#



A YOMM2 method is implemented as a singleton of an instance of the `method`
Expand All @@ -56,7 +56,7 @@ the same signature. Consider a more animal-friendly method:
struct feed_key;
using feed_method = method<feed_key, std::string(virtual_<Animal&>)>;
```
#



In the absence of the first parameter, `kick` and `feed` would be the same
Expand All @@ -78,7 +78,7 @@ std::string kick_dog(Dog& dog) {

kick_method::add_function<kick_dog> add_kick_dog;
```
#
Note that the name of the function serving as a method definition must be
Expand All @@ -100,7 +100,7 @@ std::string kick_bulldog(Bulldog& dog) {
kick_method::add_function<kick_bulldog> add_kick_bulldog(&kick_bulldog_next);
```
#



We can now call the method. The class contains a static function object named
Expand All @@ -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
Expand Down Expand Up @@ -162,7 +162,7 @@ In addition, the header provides
These macros are defined by header file `yorel/yomm2/symbols.hpp`.
#
## Trimming verbosity
Expand All @@ -177,7 +177,7 @@ Let's rewrite the example, this time using the symbol-generation macros, and
a helper.
#
(`Animal` classes same as before)
Expand All @@ -195,7 +195,7 @@ struct YOMM2_SYMBOL(kick);
using kick_method = method<YOMM2_SYMBOL(kick), std::string(virtual_<Animal&>)>;
```
#



`add_function` is a workhorse that is intended to be used directly only by
Expand All @@ -216,7 +216,7 @@ struct kick_dog {

YOMM2_STATIC(kick_method::add_definition<kick_dog>);
```
#
This may not seem like a huge improvement, until we need a `next` function.
Expand All @@ -236,7 +236,7 @@ struct kick_bulldog : kick_method::next<kick_bulldog> {
YOMM2_STATIC(kick_method::add_definition<kick_bulldog>);
```
#



Do you have doubts about the value of definition containers? Here are two
Expand Down
13 changes: 2 additions & 11 deletions docs/tutorials/custom_rtti_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#



# Using Custom RTTI
Expand Down Expand Up @@ -73,7 +73,7 @@ struct std_rtti : rtti {

template<class Stream>
static void type_name(type_id type, Stream& stream) {
stream << reinterpret_cast<const std::type_info*>(type)->name();
stream << reinterpret_cast<const std::type_info*>(type)[name](None)();
}

static std::type_index type_index(type_id type) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -222,7 +220,6 @@ Thus we create the policy with:
struct custom_policy : default_policy::rebind<custom_policy>::replace<
policy::rtti, custom_rtti> {};
```
#


Finally, we must specify the new policy during class registration and method
Expand All @@ -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
Expand Down Expand Up @@ -271,7 +267,6 @@ BOOST_AUTO_TEST_CASE(custom_rtti_demo) {
}
}
```
#


## Taking advantage of custom RTTI specificities
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -454,7 +446,6 @@ struct custom_rtti : policy::deferred_static_rtti {
}
};
```
#


The only change is that the custom facet now inherits from
Expand Down
Loading

0 comments on commit 2edef6a

Please sign in to comment.