Replies: 1 comment
-
I suppose another way of doing this that might be the best is to use templated functions: template <typename T>
auto VisitFunc(const T& arg) -> ObjVar = delete;
template <>
auto VisitFunc(const BoolScalar& arg) const -> ObjVar {
return true;
}
template <>
auto Visit(const StringScalar& arg) const -> ObjVar {
return std::string{"Hello, world!"};
}
template <>
auto Visit(const IntScalar& arg) const -> ObjVar {
return 42;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am working with fixed data types but a potentially limitless amount of algorithms to apply against those types, so I figured the visitor pattern would work well for the problems I am trying to solve. Here is a simple attempt at implementing this via nanobind:
This compiles fine, but the
BoolScalar
visit method doesn't work at runtime, assumedly since the nanobind templating expects that a member function implicitly accepts aself
argument as in Python:Are there any suggested ways to approach this problem? While
VisitorFunc
works here I was hoping to stick with a class-based structure for the algorithmsBeta Was this translation helpful? Give feedback.
All reactions