Skip to content

Can I use dynamic_cast conversion with proxy? #194

Answered by mingxwa
xuruilong100 asked this question in Q&A
Discussion options

You must be logged in to vote

@xuruilong100 Thanks for asking. dynamic_cast is not directly supported by proxy. Although it might be useful in debugging, using it in production code is usually considered a bad practice (see some interesting discussions here). Therefore, we decided not to prioritize this feature over performance by default.

However, it can be implemented with custom reflection if you really need. For example:

#include <iostream>
#include <typeinfo>

#include "proxy.h"

class RttiReflector {
 public:
  template <class T>
  constexpr explicit RttiReflector(std::in_place_type_t<T>) : type_(typeid(T)) {}

  template <class F, class R>
  struct accessor {
    const std::type_info& GetType() const noexcept {…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@mingxwa
Comment options

@xuruilong100
Comment options

@mingxwa
Comment options

@xuruilong100
Comment options

@mingxwa
Comment options

Answer selected by xuruilong100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants