diff --git a/README.md b/README.md index 0adfbf5..4fbdde9 100644 --- a/README.md +++ b/README.md @@ -48,16 +48,17 @@ Or just use the single-header version of the library, which you can find [here]( ## Manuals -- [Class](develop/manuals/meta_manuals/class_manual.cpp) -- [Enum](develop/manuals/meta_manuals/enum_manual.cpp) -- [Function](develop/manuals/meta_manuals/function_manual.cpp) -- [InPlace](develop/manuals/meta_manuals/inplace_manual.cpp) -- [Member](develop/manuals/meta_manuals/member_manual.cpp) -- [Metadata](develop/manuals/meta_manuals/metadata_manual.cpp) -- [Method](develop/manuals/meta_manuals/method_manual.cpp) -- [Scopes](develop/manuals/meta_manuals/scopes_manual.cpp) -- [UValue](develop/manuals/meta_manuals/uvalue_manual.cpp) -- [Variable](develop/manuals/meta_manuals/variable_manual.cpp) +- [class](develop/manuals/meta_manuals/class_manual.cpp) +- [enum](develop/manuals/meta_manuals/enum_manual.cpp) +- [function](develop/manuals/meta_manuals/function_manual.cpp) +- [inplace](develop/manuals/meta_manuals/inplace_manual.cpp) +- [member](develop/manuals/meta_manuals/member_manual.cpp) +- [metadata](develop/manuals/meta_manuals/metadata_manual.cpp) +- [method](develop/manuals/meta_manuals/method_manual.cpp) +- [scopes](develop/manuals/meta_manuals/scopes_manual.cpp) +- [ucast](develop/manuals/meta_manuals/ucast_manual.cpp) +- [uvalue](develop/manuals/meta_manuals/uvalue_manual.cpp) +- [variable](develop/manuals/meta_manuals/variable_manual.cpp) ## Features diff --git a/ROADMAP.md b/ROADMAP.md index 54b08e0..1978c68 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -3,10 +3,9 @@ ## Backlog - type conversions -- non-linear search of methods/functions/... - fix all includes to work with the library more flexible - test and support shared libraries -- add ucast manual +- add debug type names ## Version 1.0 @@ -17,4 +16,3 @@ - static binds listener - dynamic type visitor - conan package config -- type names by [nameof](https://github.com/Neargye/nameof) diff --git a/develop/manuals/meta_manuals/ucast_manual.cpp b/develop/manuals/meta_manuals/ucast_manual.cpp new file mode 100644 index 0000000..635fc07 --- /dev/null +++ b/develop/manuals/meta_manuals/ucast_manual.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2023, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +#include +#include + +namespace +{ + // we should add META_HPP_ENABLE_POLY_INFO macro inside every class + // to add polymorphic information to our inheritance hierarchy + + // after this we will be able to use the library's polymorphic functions + // like `ucast` or `resolve_type(T&&)` + + struct A { META_HPP_ENABLE_POLY_INFO() }; + struct B { META_HPP_ENABLE_POLY_INFO() }; + struct C : A, B { META_HPP_ENABLE_POLY_INFO(A, B) }; +} + +TEST_CASE("meta/meta_manuals/ucast") { + namespace meta = meta_hpp; + + C c{}; + + A& a = c; + B& b = c; + + // functions `ucast` and `resolve_type(T&&)` rely on polymorphic information + // are provided in META_HPP_ENABLE_POLY_INFO macro + + // we can use polymorphic type resolving to get most derived class type + CHECK(meta::resolve_type(a) == meta::resolve_type()); + + // and cast our pointers and references like dynamic_cast does + CHECK(&c == &meta::ucast(a)); + + // `ucast` supports cross casts, multiple and virtual inheritance as well + CHECK(&a == meta::ucast(&b)); +}