diff --git a/README.md b/README.md index 7c11fe8..b86911a 100644 --- a/README.md +++ b/README.md @@ -256,16 +256,13 @@ of mixins. Making an easy concrete class that doesn't need to initialize things: ```cpp -struct concrete : ciabatta::mixin { -}; +using concrete = ciabatta::mixin; ``` -Or maybe something more complicated that does initialize things: +Or maybe something more complicated that needs to initialize things: ```cpp -struct concrete2 : ciabatta::mixin { - concrete2(std::ostream& out_) : mixin(out_, "my prefix") {} -}; +using concrete2 = ciabatta::mixin; ``` For completeness, the test driver: @@ -275,7 +272,7 @@ int main() { concrete c; c.frobnicate(); - concrete2 c2{std::cerr}; + concrete2 c2{std::cerr, "my_prefix"}; c2.frobnicate(); } ``` @@ -336,8 +333,7 @@ struct is_socket : Base, abstract_socket { And now we can make our concrete `null_socket` class: ```cpp -struct null_socket - : ciabatta::mixin {}; +using null_socket = ciabatta::mixin; ``` *Note:* `is_socket` has to be last if you want the ability to mark member @@ -347,11 +343,10 @@ If you don't want to define a new class just to inject an abstract interface, *ciabatta* has your back: ```cpp -struct null_socket2 - : ciabatta::mixin::mixin> {}; +using null_socket2 = ciabatta::mixin< + null_sender, + null_receiver, + ciabatta::mixins::provides::mixin>; ``` ### Templated Mixins @@ -373,13 +368,10 @@ To use `provides` as-is, we can just supply the `interface` parameter to `curry`, like so: ```cpp -struct null_socket3 - : ciabatta::mixin< - null_socket3, - null_sender, - null_receiver, - ciabatta::curry::mixin> { -}; +using null_socket3 = ciabatta::mixin< + null_sender, + null_receiver, + ciabatta::curry::mixin>; ``` In fact, this is what `ciabatta::mixins::provides` does with its `mixin` diff --git a/include/ciabatta/ciabatta.hpp b/include/ciabatta/ciabatta.hpp index 9165f65..fd42de7 100644 --- a/include/ciabatta/ciabatta.hpp +++ b/include/ciabatta/ciabatta.hpp @@ -61,16 +61,21 @@ struct chain_inherit { template class... Mixins> using mixin_impl = typename chain_inherit, Mixins...>::type; - -} // namespace detail - + template class... Mixins> -struct mixin : ::ciabatta::detail::mixin_impl { +struct mixin_base : ::ciabatta::detail::mixin_impl { template - constexpr mixin(Rest&&... rest) + constexpr mixin_base(Rest&&... rest) : ::ciabatta::detail::mixin_impl( static_cast(rest)...) {} +}; + +} // namespace detail +template