C++ Reflection Library

Version Travis status Appveyor status Coverage Status CII Best Practices Codacy Badge Documentation License Donate

!New Release - 0.9.6!

RTTR

C++ Reflection Library

RTTR stands for Run Time Type Reflection. It describes the ability of a computer program to introspect and modify an object at runtime. It is also the name of the library itself, which is written in C++ and released as open source library. You can find more information on: www.rttr.org


How to Use

Manual registration

#include <rttr/registration>
using namespace rttr;

struct MyStruct { MyStruct() {}; void func(double) {}; int data; };

RTTR_REGISTRATION
{
    registration::class_<MyStruct>("MyStruct")
         .constructor<>()
         .property("data", &MyStruct::data)
         .method("func", &MyStruct::func);
}

Iterate over members

type t = type::get<MyStruct>();
for (auto& prop : t.get_properties())
    std::cout << "name: " << prop.get_name();

for (auto& meth : t.get_methods())
    std::cout << "name: " << meth.get_name();

Constructing types

type t = type::get_by_name("MyStruct");
variant var = t.create();    // will invoke the previously registered ctor

constructor ctor = t.get_constructor();  // 2nd way with the constructor class
var = ctor.invoke();
std::cout << var.get_type().get_name(); // prints 'MyStruct'

Set/get properties

MyStruct obj;

property prop = type::get(obj).get_property("data");
prop.set_value(obj, 23);

variant var_prop = prop.get_value(obj);
std::cout << var_prop.to_int(); // prints '23'

Invoke Methods:

MyStruct obj;

method meth = type::get(obj).get_method("func");
meth.invoke(obj, 42.0);

variant var = type::get(obj).create();
meth.invoke(var, 42.0);

Features

  • reflect constructors, methods, data member or enums
  • classes; with single-, multiple- and virtual-inheritance
  • constructors (arbitrary argument count)
  • methods (virtual, abstract, overloaded, arbitrary argument count)
  • arrays (incl. raw-arrays; arbitrary dimension count)
  • ability to invoke properties and methods of classes from any arbitrary class level
  • no header pollution; the reflection information is created in the cpp file to minimize compile time when modifying the data
  • working with custom types without the need of having the declaration of the type available at compile time (useful for plugins)
  • possibility to add additional metadata to all reflection objects
  • possibility to add default arguments to methods or constructors
  • adjust registration behaviour through policies
  • minimal macro usage
  • no additional 3rd party dependencies are needed
  • no rtti required; contains a faster and across shared libraries working replacement
  • no exceptions (this feature come with cost and is also regularly disabled on consoles)
  • no external compiler or tool needed, only standard ISO C++11

Portability

Tested and compiled with:

  • Microsoft Visual Studio 2015 & 2017 (2013 support till version 0.9.6)
  • GCC 4.8.1
  • Clang 3.7
  • MinGW 4.8.2

License

RTTR is released under the terms of the MIT license, so it is free to use in your free or commercial projects.

Copyright (c) 2014 - 2018 Axel Menzel [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Installation

The installation guide can be found here.

Get Started:

Take a look at the documentation or start with the tutorial.

Donation:

When you use RTTR and you would like to say thank you for its development, I am happy to receive any donation.

paypal

Owner
rttr.org
A library for reflection in C++
rttr.org
Comments
  • Add new library class

    Add new library class

    This adds the functionality to load libraries in a simple cross platform way.

    The native OS calls are wrapped behind a class interface.

    Highlights:

    • handling of file suffixes (.dll or .so)
    • automatic unload of library on program exit
    • retrieving of loaded types in library
    • avoid of unnecessary loading calls, when same plugin is loaded multiple times

    additional:

    • added unit tests
    • added example of loading a plugin
  • added support for c++17 compilers

    added support for c++17 compilers

    a lot of warning poped up from g++7 "will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type]" These can be remove when compiling with c++17 compiler flag

    Additionally: VS2015 and greater will now use noexcept, was not enabled by accident The benchmarks has to be disabled, because of compile errors in noniuose (no warnings) https://github.com/libnonius/nonius/issues/97

  • clang 7.0 support - individual warning levels

    clang 7.0 support - individual warning levels

    this not a really good pull request, I started it, to keep working on these c++17 warnings...

    • there are two warnings regarding array bound checks somewhere in the catch.hpp dependency (think its marco expansion?)
    /Users/gabrielnuetzi/Desktop/rttr/src/rttr/../rttr/detail/impl/array_range_impl.h: In function 'void ____C_A_T_C_H____T_E_S_T____139()':
    /Users/gabrielnuetzi/Desktop/rttr/src/rttr/../rttr/detail/impl/array_range_impl.h:200:105: warning: array subscript is below array bounds [-Warray-bounds]
         return (empty_() ? const_reverse_iterator{m_begin, this} : const_reverse_iterator{m_begin - 1, this});
    
    • lots of no-except warnings:
    /Users/gabrielnuetzi/Desktop/rttr/src/rttr/../rttr/detail/registration/registration_impl.h:205:60: error: mangled name for 'rttr::registration::bind<rttr::detail::meth, Class_Type, F, acc_level> rttr::registration::class_<Class_Type>::method(rttr::string_view, F, acc_level) [with F = long unsigned int (std::__cxx11::basic_string<char>::*)() const noexcept; acc_level = rttr::detail::public_access; Class_Type = std::__cxx11::basic_string<char>]' will change in C++17 because the exception specification is part of a function type [-Werror=noexcept-type]
     registration::bind<detail::meth, Class_Type, F, acc_level> registration::class_<Class_Type>::method(string_view name, F f, acc_level level)
    
  • new release?

    new release?

    Hi, first of all thanks so much for all the work on rttr, it is invaluable to me!

    I am wondering, is there going to be another "release" at some stage? There are a lot of improvements in the code base since 0.9.5, but for various reasons there are projects where I can't use a dependency without a "named" version - if not a release, perhaps just some tagged commit / branch more recent than the 0.9.5 version?

    Thanks!

  • Variant upcasting

    Variant upcasting

    Hi there! I'm trying to cast a variant hold a shared_ptr<Derived> of a derived class to a shared_ptr<Base> of its base class (i.e. upcasting). I've searched previous issues and it seems like others attempted this as well, e.g. in #56. Similar to #56, my use-case concerns object serialization: I would like to serialize and deserialize an object of Derived via a shared_ptr<Base>. Serialization is fine as I can easily obtain the most derived type of a given variant, but deserialization (obtaining shared_ptr<Base> from a reconstructed shared_ptr<Derived> RTTR variant) does not seem to work.

    The documentation of variant::convert mentions that it supports "Conversion of raw pointers to its derived types, if a rttr_cast to the type described by target_type would succeed," but I'm wondering why there's no support for casting to base types.

  • signal abort when using boost recursive_directory_iterator

    signal abort when using boost recursive_directory_iterator

    boost 1.64 cygwin RTTR_VERSION 907

    sample code:

    #include <iostream>
    #include <boost/filesystem.hpp>
    int main() {
        boost::filesystem::recursive_directory_iterator it(boost::filesystem::path("./"));
        std::cout << "Hello, World!" << std::endl;
        return 0;
    }
    

    it will get signal abort if link with RTTR::Core_Lib.

    fails on boost/filesystem/operations: directory_iterator_construct: Line 2391

    it.m_imp->dir_entry.assign(p / filename, file_stat, symlink_file_stat);
    
  • Conan package

    Conan package

    I have ported my previous conan package to the newer version and in source build. I have tested it so far on linux and OSX.

    I will try and get to testing on windows, I won't have an opportunity for a week or so, you may want to hold off accepting until then, but if not the PR is here.

  • Bugfix warning level

    Bugfix warning level

    Added -Wall and /W4 to compilers and remove all popped up warnings Breaking change: use: #include <rttr/registration_friend> in order to register private members.

    fixes #67

  • strange compile error: clang7.0

    strange compile error: clang7.0

    I have a simple use case which compiles fine: https://github.com/gabyx/ExecutionGraph/blob/c4b1cccfd855d418dfb3fe53b2cc257aaabcbf14/tests/src/main_Factory.cpp#L36

    In another target, I am not even using registration, only RTTR_ENABLE(...). I get some strange errors: Backend.hpp

    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/string_view.h:498:
    In file included from /usr/local/opt/rttr/include/rttr/detail/impl/string_view_impl.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/detail/misc/utility.h:34:
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:464:79: error: expected member name or ';' after declaration specifiers
            template <typename U> static NoType& check(typename U::no_array_type*);
                                  ~~~~~~~~~~~~~                                   ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:465:57: error: expected member name or ';' after declaration specifiers
            template <typename U> static YesType& check(...);
                                  ~~~~~~~~~~~~~~            ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:468:61: error: use of undeclared identifier 'check'
            static RTTR_CONSTEXPR_OR_CONST bool value = (sizeof(check<array_mapper<T> >(0)) == sizeof(YesType));
                                                                ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:468:83: error: expected '(' for function-style cast or type construction
            static RTTR_CONSTEXPR_OR_CONST bool value = (sizeof(check<array_mapper<T> >(0)) == sizeof(YesType));
                                                                      ~~~~~~~~~~~~~~~ ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:483:75: error: expected member name or ';' after declaration specifiers
            template <typename U> static YesType& check(typename U::is_valid*);
                                  ~~~~~~~~~~~~~~                              ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:484:56: error: expected member name or ';' after declaration specifiers
            template <typename U> static NoType& check(...);
                                  ~~~~~~~~~~~~~            ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:487:61: error: use of undeclared identifier 'check'
            static RTTR_CONSTEXPR_OR_CONST bool value = (sizeof(check<T>(0)) == sizeof(YesType));
                                                                ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:487:67: error: 'T' does not refer to a value
            static RTTR_CONSTEXPR_OR_CONST bool value = (sizeof(check<T>(0)) == sizeof(YesType));
                                                                      ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:477:24: note: declared here
        template <typename T>
                           ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:504:31: error: use of undeclared identifier 'check'
            using type = decltype(check<T>(nullptr));
                                  ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:504:37: error: 'T' does not refer to a value
            using type = decltype(check<T>(nullptr));
                                        ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:498:24: note: declared here
        template <typename T>
                           ^
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:472:51: error: non-type template argument is not a constant expression
        using is_array = std::integral_constant<bool, is_array_impl<remove_cv_t< remove_reference_t<T> > >::value>;
                                                      ^
    /usr/local/opt/rttr/include/rttr/detail/variant_array_view/variant_array_view_traits.h:48:81: note: in instantiation of template type alias 'is_array' requested here
    using can_create_array_container = std::integral_constant<bool, ::rttr::detail::is_array<T>::value || is_wrapper_array_type<T>::value || is_pointer_array_type<T>::value>;
                                                                                    ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:298:24: note: in instantiation of template type alias 'can_create_array_container' requested here
                    return can_create_array_container<T>::value;
                           ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/string_view.h:498:
    In file included from /usr/local/opt/rttr/include/rttr/detail/impl/string_view_impl.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/detail/misc/utility.h:34:
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:491:68: error: non-type template argument is not a constant expression
        using is_associative_container = std::integral_constant<bool, !has_is_valid_alias<associative_container_mapper<Tp> >::value>;
                                                                       ^
    /usr/local/opt/rttr/include/rttr/detail/variant_associative_view/variant_associative_view_creator.h:46:66: note: in instantiation of template type alias 'is_associative_container' requested here
    using can_create_associative_view = std::integral_constant<bool, is_associative_container<raw_type_t<wrapper_address_return_type_t<T>>>::value>;
                                                                     ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:302:24: note: in instantiation of template type alias 'can_create_associative_view' requested here
                    return can_create_associative_view<T>::value;
                           ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/string_view.h:498:
    In file included from /usr/local/opt/rttr/include/rttr/detail/impl/string_view_impl.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/detail/misc/utility.h:34:
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:494:67: error: non-type template argument is not a constant expression
        using is_sequential_container = std::integral_constant<bool, !has_is_valid_alias<sequential_container_mapper<Tp > >::value>;
                                                                      ^
    /usr/local/opt/rttr/include/rttr/detail/variant_sequential_view/variant_sequential_view_creator.h:46:65: note: in instantiation of template type alias 'is_sequential_container' requested here
    using can_create_sequential_view = std::integral_constant<bool, is_sequential_container<raw_type_t<wrapper_address_return_type_t<T>>>::value>;
                                                                    ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:306:24: note: in instantiation of template type alias 'can_create_sequential_view' requested here
                    return can_create_sequential_view<T>::value;
                           ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:1189:
    In file included from /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:36:
    In file included from /usr/local/opt/rttr/include/rttr/detail/type/get_create_variant_func.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/variant.h:1079:
    In file included from /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:36:
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:310:73: error: no matching function for call to 'create_variant_array_view'
                    arg.get_value<std::unique_ptr<array_wrapper_base>&>() = create_variant_array_view(const_cast<T&>(Tp::get_value(src_data)));
                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    /usr/local/opt/rttr/include/rttr/detail/variant_array_view/variant_array_view_creator_impl.h:42:1: note: candidate template ignored: substitution failure [with T = bool &, Tp = bool]: non-type template argument is not a constant expression
    create_variant_array_view(T&& value)
    ^
    /usr/local/opt/rttr/include/rttr/detail/variant_array_view/variant_array_view_creator_impl.h:51:1: note: candidate template ignored: substitution failure [with T = bool &, Tp = bool]: non-type template argument is not a constant expression
    create_variant_array_view(T&& value)
    ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:1189:
    In file included from /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:36:
    In file included from /usr/local/opt/rttr/include/rttr/detail/type/get_create_variant_func.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/variant.h:1079:
    In file included from /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:36:
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:315:70: error: no matching function for call to 'create_variant_associative_view'
                    arg.get_value<variant_associative_view_private&>() = create_variant_associative_view(const_cast<T&>(Tp::get_value(src_data)));
                                                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/opt/rttr/include/rttr/detail/variant_associative_view/variant_associative_view_creator_impl.h:42:1: note: candidate template ignored: substitution failure [with T = bool &, Tp = bool]: non-type template argument is not a constant expression
    create_variant_associative_view(T&& value)
    ^
    /usr/local/opt/rttr/include/rttr/detail/variant_associative_view/variant_associative_view_creator_impl.h:51:1: note: candidate template ignored: substitution failure [with T = bool &, Tp = bool]: non-type template argument is not a constant expression
    create_variant_associative_view(T&& value)
    ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:1189:
    In file included from /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:36:
    In file included from /usr/local/opt/rttr/include/rttr/detail/type/get_create_variant_func.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/variant.h:1079:
    In file included from /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:36:
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:320:69: error: no matching function for call to 'create_variant_sequential_view'
                    arg.get_value<variant_sequential_view_private&>() = create_variant_sequential_view(const_cast<T&>(Tp::get_value(src_data)));
                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/opt/rttr/include/rttr/detail/variant_sequential_view/variant_sequential_view_creator_impl.h:42:1: note: candidate template ignored: substitution failure [with T = bool &, Tp = bool]: non-type template argument is not a constant expression
    create_variant_sequential_view(T&& value)
    ^
    /usr/local/opt/rttr/include/rttr/detail/variant_sequential_view/variant_sequential_view_creator_impl.h:51:1: note: candidate template ignored: substitution failure [with T = bool &, Tp = bool]: non-type template argument is not a constant expression
    create_variant_sequential_view(T&& value)
    ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/string_view.h:498:
    In file included from /usr/local/opt/rttr/include/rttr/detail/impl/string_view_impl.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/detail/misc/utility.h:34:
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:472:51: error: non-type template argument is not a constant expression
        using is_array = std::integral_constant<bool, is_array_impl<remove_cv_t< remove_reference_t<T> > >::value>;
                                                      ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_data.h:317:92: note: in instantiation of template type alias 'is_array' requested here
                                                  TYPE_TRAIT_TO_BITSET_VALUE_2(::rttr::detail::is_array, is_array) |
                                                                                               ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:302:74: note: in instantiation of function template specialization 'rttr::detail::make_type_data<bool>' requested here
            static const type val = get_registration_manager<int>().add_item(make_type_data<T>());
                                                                             ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:390:105: note: in instantiation of member function 'rttr::detail::type_getter<bool, void>::get_type' requested here
        return detail::type_getter<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::get_type();
                                                                                                            ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:268:47: note: in instantiation of function template specialization 'rttr::type::get<bool>' requested here
                    arg.get_value<type>() = type::get<T>();
                                                  ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/string_view.h:498:
    In file included from /usr/local/opt/rttr/include/rttr/detail/impl/string_view_impl.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/detail/misc/utility.h:34:
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:472:51: error: non-type template argument is not a constant expression
        using is_array = std::integral_constant<bool, is_array_impl<remove_cv_t< remove_reference_t<T> > >::value>;
                                                      ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_data.h:317:92: note: in instantiation of template type alias 'is_array' requested here
                                                  TYPE_TRAIT_TO_BITSET_VALUE_2(::rttr::detail::is_array, is_array) |
                                                                                               ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:302:74: note: in instantiation of function template specialization 'rttr::detail::make_type_data<bool *>' requested here
            static const type val = get_registration_manager<int>().add_item(make_type_data<T>());
                                                                             ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:390:105: note: in instantiation of member function 'rttr::detail::type_getter<bool *, void>::get_type' requested here
        return detail::type_getter<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::get_type();
                                                                                                            ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:290:61: note: in instantiation of function template specialization 'rttr::type::get<bool *>' requested here
                    data.m_type                         = type::get< raw_addressof_return_type_t<T> >();
                                                                ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/mac/AppMac.mm:18:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/AppHandler.hpp:21:
    In file included from /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/backend/Backend.hpp:17:
    In file included from /usr/local/opt/rttr/include/rttr/type:31:
    In file included from /usr/local/opt/rttr/include/rttr/type.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/string_view.h:498:
    In file included from /usr/local/opt/rttr/include/rttr/detail/impl/string_view_impl.h:32:
    In file included from /usr/local/opt/rttr/include/rttr/detail/misc/utility.h:34:
    /usr/local/opt/rttr/include/rttr/detail/misc/misc_type_traits.h:472:51: error: non-type template argument is not a constant expression
        using is_array = std::integral_constant<bool, is_array_impl<remove_cv_t< remove_reference_t<T> > >::value>;
                                                      ^
    /usr/local/opt/rttr/include/rttr/detail/variant_array_view/variant_array_view_traits.h:48:81: note: in instantiation of template type alias 'is_array' requested here
    using can_create_array_container = std::integral_constant<bool, ::rttr::detail::is_array<T>::value || is_wrapper_array_type<T>::value || is_pointer_array_type<T>::value>;
                                                                                    ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:298:24: note: in instantiation of template type alias 'can_create_array_container' requested here
                    return can_create_array_container<T>::value;
                           ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool *, rttr::detail::variant_data_policy_small<bool *, rttr::detail::empty_type_converter<bool *> >, rttr::detail::empty_type_converter<bool *> >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/type/get_create_variant_func.h:58:16: note: in instantiation of function template specialization 'rttr::variant::variant<bool *&, bool *>' requested here
            return data.get_value<T>();
                   ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_data.h:307:54: note: in instantiation of member function 'rttr::detail::create_variant_policy<bool *>::create_variant' requested here
                                &create_variant_func<T>::create_variant,
                                                         ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:302:74: note: in instantiation of function template specialization 'rttr::detail::make_type_data<bool *>' requested here
            static const type val = get_registration_manager<int>().add_item(make_type_data<T>());
                                                                             ^
    /usr/local/opt/rttr/include/rttr/detail/type/type_impl.h:390:105: note: in instantiation of member function 'rttr::detail::type_getter<bool *, void>::get_type' requested here
        return detail::type_getter<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::get_type();
                                                                                                            ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_policy.h:290:61: note: in instantiation of function template specialization 'rttr::type::get<bool *>' requested here
                    data.m_type                         = type::get< raw_addressof_return_type_t<T> >();
                                                                ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_impl.h:55:43: note: in instantiation of member function 'rttr::detail::variant_data_base_policy<bool, rttr::detail::variant_data_policy_arithmetic<bool>, rttr::detail::default_type_converter<bool, rttr::detail::convert_from<bool> > >::invoke' requested here
    :   m_policy(&detail::variant_policy<Tp>::invoke)
                                              ^
    /usr/local/opt/rttr/include/rttr/detail/variant/variant_data_converter.h:283:31: note: in instantiation of function template specialization 'rttr::variant::variant<const bool &, bool>' requested here
            return to_enumeration(from, to);
                                  ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    

    can you make up anything from this? Why does he need rttr::variant::variant<const bool &, bool>

    I am nowhere using an rttr::variant

  • BUG - get_method/property uses

    BUG - get_method/property uses "base" rather than "most derived"

    If you register the same function name in a derived class and in a base class and call the function via a derived instance

    C++ calls the derived method RTTR calls the base method

    RTTR searches from the "base class" to the derived class for the matching name.

    The linear search of prop/meth vecs must use reverse iterator

    staring from the most derived class registered.

  • get_class_method iterates over all methods which is slow

    get_class_method iterates over all methods which is slow

    When a user needs to call a method having it's string name, then this would be called:

    for (; itr != m_class_method_list.cend(); ++itr) { auto& item = *itr; if (item.m_class_id != raw_type.get_id()) break;

        if (item.m_name_hash != name_hash)
            break;
    
        if (std::strcmp(item.m_data->get_name(), name) == 0)
            return item.m_data.get();
    }
    

    This is slow. Qt does it by generating a switch statement. The overhead could be solved with modern c++1x as well.

  • Cannot compile json_example in C++17

    Cannot compile json_example in C++17

    I get a warning STL4015: The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17,when i compile the json_example project. It seem like a problem of rapidjson,and it has been fixed in https://github.com/Tencent/rapidjson/pull/1137

  • how to insert a class instrance into sequential view without get its wrapped value?

    how to insert a class instrance into sequential view without get its wrapped value?

    hi, Sir

    I am creating a generic binary serializer, and got block on how to insert class instancec into a sequential view. here is the example code:

    #include <iostream>
    #include <rttr/type>
    #include <rttr/registration.h>
    using namespace rttr;
    
    struct Item {
        int i ;
    };
    struct MyTestClass {
        std::vector<Item> seq;
    };
    
    RTTR_REGISTRATION
    {
        using namespace rttr;
        registration::class_<MyTestClass>("TestClass")
            .constructor<>()
            .property("seq", &MyTestClass::seq);
    
        registration::class_<Item>("Item")
            .constructor<>()
            .property("item", &Item::i);
    
    }
    
    void CreateInst(rttr::instance inst) {
        auto localobj = inst.get_type().get_raw_type().is_wrapper() ? inst.get_wrapped_instance() : inst;
        auto p = localobj.get_type().get_property("item");
        p.set_value(inst, 100);
    }
    
    int main()
    {
        MyTestClass inst;
        for (auto prop : rttr::type::get_by_name("TestClass").get_properties()) {
            auto type = prop.get_type();
    
            if (type.is_sequential_container()) {
                auto val = prop.get_value(inst);
                auto view =val.create_sequential_view();
                view.set_size(1); //just for demo
                rttr::variant var = view.get_value_type().create();
                CreateInst(var);
                //Item item=var.get_wrapped_value<Item>(); 
                view.set_value(0, var);
                prop.set_value(inst, val);
            }
        }
        std::cout << inst.seq[0].i << std::endl;
    
    }
    

    it always output '0' instead of '100' on screen, unless I get its wrapped value and insert. that is not what I want, because a serializer shall know nothing about his customer's type.

    Could you help me to improve on this ?

    Thank you.

    BR Ray

  • Crash when trying to load library.

    Crash when trying to load library.

    I'm trying to load a dll that is registering types to rttr. But the application crashes when callling library.Load(). Apparently the issue is triggered here: array_range<type> type::get_types() RTTR_NOEXCEPT { auto& type_list = detail::type_register_private::get_instance().get_type_storage(); return array_range<type>(&type_list[1], type_list.size() - 1); } type_list has only 1 element, so it is out of bounds when accessing like type_list[1] i guess. Maybe I am doing something wrong. I've been following the documentation though. My dll has in a cpp file the following: `#include "components.h" #include <rttr/registration> using namespace rttr;

    RTTR_PLUGIN_REGISTRATION { rttr::registration::class_("test") .constructor<>() .property("i", &test::i);

    rttr::registration::class_<test2>("test2")
    .constructor<>()
    .property("d", &test2::d);
    

    } And my application is trying to load it like this:library lib("game_gameplay"); // file suffix is not needed, will be automatically appended lib.load();`

    It crashes after calling load. AFAIK it is everything needed according to the documentation. Am I missing something. dll is properly created. And I've been able to load it and get func ptr using windows API. But I'd like to use rttr method.

  • How to register int[] property in a struct?

    How to register int[] property in a struct?

    #include <rttr/registration>
    
    struct MyStruct { MyStruct() {}; int data[3]; };
    
    RTTR_REGISTRATION
    {
        using namespace rttr;
    
        registration::class_<MyStruct>("MyStruct")
          .constructor<>()
          .property("data", &MyStruct::data);
    }
    
    int main() {
        return 0;
    }
    

    Compile error: error C2668: 'operator new[]': ambiguous call to overloaded function

  • Any method to detect the METADATA conflicts?

    Any method to detect the METADATA conflicts?

    I add two metadata with a conflict key under the same property

    		registration::property("value", &g_value)(
    			metadata(ASN1_ATTRIBUTE_TAG, ASN1IntegerAttr {.name = "Data" }),
    			metadata(ASN1_ATTRIBUTE_TAG, ASN1BooleanAttr {.name = "Flag"})
    
    			);
    

    When running unit test, it looks only 1st metadata is reserved, however, I hope this conflict can be reported at runtime? is there any method to force it throws exceptions instead of ignore the conflict?

A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

Dec 12, 2022
Customizable C++17 Runtime Reflection Library

Refureku Check the Wiki for more documentation and use examples! Refureku is a powerful C++17 RTTI free runtime reflection library based on Kodgen. It

Dec 28, 2022
A modern compile-time reflection library for C++ with support for overloads, templates, attributes and proxies

refl-cpp v0.12.1 Documentation refl-cpp encodes type metadata in the type system to allow compile-time reflection via constexpr and template metaprogr

Dec 31, 2022
A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

Jan 7, 2023
C++ Reflection Parser / Runtime Skeleton

C++ Reflection Preface I worked on a complete reflection pipeline starting in the summer of 2015 for a game project / editor. My intent by creating th

Dec 24, 2022
Header-only, non-intrusive and macro-free runtime reflection system in C++

Header-only runtime reflection system in C++ The reflection system was born within EnTT and is developed and enriched there. This project is designed

Jan 4, 2023
A compiling time static reflection framework for C++

static_reflect This is a fully compiling time static reflection lightweight framework for C++. It provides a very rich compile-time reflection functio

Dec 25, 2022
cpgf library

cpgf library cpgf library is a cross platform C++ library for callback, reflection, serialization and script binding. It's written in standard C++ and

Sep 13, 2022
C++ Reflection Library

!New Release - 0.9.6! RTTR C++ Reflection Library RTTR stands for Run Time Type Reflection. It describes the ability of a computer program to introspe

Jan 3, 2023
A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

Dec 12, 2022
Customizable C++17 Runtime Reflection Library

Refureku Check the Wiki for more documentation and use examples! Refureku is a powerful C++17 RTTI free runtime reflection library based on Kodgen. It

Dec 28, 2022
A modern compile-time reflection library for C++ with support for overloads, templates, attributes and proxies

refl-cpp v0.12.1 Documentation refl-cpp encodes type metadata in the type system to allow compile-time reflection via constexpr and template metaprogr

Dec 31, 2022
A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

Jan 7, 2023
Cista is a simple, high-performance, zero-copy C++ serialization & reflection library.

Simple C++ Serialization & Reflection. Cista++ is a simple, open source (MIT license) C++17 compatible way of (de-)serializing C++ data structures. Si

Jan 2, 2023
This project contains a library for C++ AST parsing, metaprogramming and reflection

Meta C++ This project contains a library for C++ AST parsing, metaprogramming and reflection. Also included is a tool for generating the necessary met

Dec 15, 2022
SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.

SPIRV-Reflect SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications. SPIRV-Ref

Dec 26, 2022
C++ Reflection Parser / Runtime Skeleton

C++ Reflection Preface I worked on a complete reflection pipeline starting in the summer of 2015 for a game project / editor. My intent by creating th

Dec 24, 2022
Header-only, non-intrusive and macro-free runtime reflection system in C++

Header-only runtime reflection system in C++ The reflection system was born within EnTT and is developed and enriched there. This project is designed

Jan 4, 2023