visitor-pattern

Acyclic Visitor C++

此生再无相见时 提交于 2021-01-29 04:13:05
问题 I'm reading the book by Alexandrescu, and I've run into the Acyclic Visitor pattern. I think that it's possible to get rid of the macross that calls AcceptImpl method of the BaseVisitable class. Could you tell me, whether the following implementation bellow conforms the standard? class BaseVisitor { public: virtual ~BaseVisitor() {} }; template <class SpecificVisitable> class SpecificVisitor { public: virtual void Visit(SpecificVisitable& t) = 0; protected: ~SpecificVisitor() {} }; template

Would a template work for std::variant's visit?

和自甴很熟 提交于 2021-01-27 20:06:40
问题 Earlier I asked this question about std::variant . Considering that the types hold by the variant are all printable by std::cout , is there a simple way to implement a visitor? Here for example, all the way down you have several lambdas to cover each type, but all do the same thing (except std::string ): std::cout << arg << ' '; . Is there a way to not repeat my self? std::visit(overloaded { [](int arg) { std::cout << arg; }, [](long arg) { std::cout << arg; }, [](double arg) { std::cout <<

Is it possible to invoke a function with a unaryPlus in kotlin?

纵饮孤独 提交于 2021-01-05 07:19:25
问题 This is a followup question on another question I asked yesterday. How can I build a nested list using builder pattern? Credit to: Pelocho for giving nice answer. I used this Tutorial to do a type safe graphQL query builder: What I want to do now is to simplify what I made And I know that kotlin must have some nice features to do that. Right now I have to invoke functions when I want to add an entity to my query: fun main() { events{ title() // I don't like to do () when it is an edge case }

async/await and the visitor pattern [closed]

孤街浪徒 提交于 2020-04-13 07:04:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 days ago . We've recently transformed one of our visitors for an object tree-like structure (that is about 40 levels deep) to the async/await pattern because the innermost accept methods now perform work which uses async/await. Everything works fine except when an exception is thrown deep in the call graph, then we run into

When “if else”/“instance of” are inevitable, how do we improve the design apart from using visitor pattern?

偶尔善良 提交于 2020-01-23 07:07:52
问题 When we have an object hierarchy that is purely a inheritance of semantic and not of behaviors,then inevitably we need to write "instanceof" or "if/else" everywhere to do run time type checking. E.g. If I have a object hierarchy which has Class Function Class Average extends Function Class Sum extends Function Class Max extends Function If there is a method called calculate() in these classes, then we do not have problem, we can just take the advantage of polymorphism and this design

Generic visitor base class template in C++ - overload issue

﹥>﹥吖頭↗ 提交于 2020-01-13 03:55:40
问题 I thought it would be a simple exercise to write a generic visitor base class template. The goal is to be able to write typedef visitor<some_base, some_derived1, some_derived2> my_visitor; ...and then have my_visitor be a type that is functionally equivalent to struct my_visitor { virtual void visit(some_base&) {} virtual void visit(some_derived1&) {} virtual void visit(some_derived2&) {} }; which i can inherit with actually useful derived visitor classes for that type hierarchy, which

Building a control-flow graph from an AST with a visitor pattern using Java

淺唱寂寞╮ 提交于 2020-01-12 03:53:08
问题 I'm trying to figure out how to implement my LEParserCfgVisitor class as to build a control-flow graph from an Abstract-Syntax-Tree already generated with JavaCC. I know there are tools that already exist, but I'm trying to do it in preparation for my Compilers final. I know I need to have a data structure that keeps the graph in memory, and I want to be able to keep attributes like IN, OUT, GEN, KILL in each node as to be able to do a control-flow analysis later on. My main problem is that I

Looking for the opposite of SqlGeometryBuilder: How can I decompose a SqlGeometry?

感情迁移 提交于 2020-01-07 02:50:06
问题 I know how to compose a SqlGeometry using SqlGeometryBuilder , for example: // using Microsoft.SqlServer.Types; SqlGeometryBuilder geometryBuilder = new SqlGeometryBuilder(); geometryBuilder.SetSrid(…); geometryBuilder.BeginGeometry(OpenGisGeometryType.Polygon); geometryBuilder.BeginFigure(0, 0); geometryBuilder.AddLine(…); … geometryBuilder.EndFigure(); geometryBuilder.EndGeometry(); SqlGeometry geometry = geometryBuilder.ConstructedGeometry; Once a SqlGeometry is built, it's pretty much an

Which design pattern could be used for a shape editor? Visitor pattern in use for now

﹥>﹥吖頭↗ 提交于 2020-01-06 21:22:37
问题 In hindsight of my question from earlier about the usage of the visitor pattern for a shape editor I came to the conclusion that I have to break the design rules of it. Mainly because I need to update my Shape fields, so essentially I need to pass arguments back to the visitor. Right now I am population the UI fields with the variables of the ShapeObject. public class Editor implements ShapeVisitor{ private Shape shape; @Override public Foo visit(CircleObject circle) { // populate fields

Forward Declaration of Template Class (Visitor Design Pattern)

寵の児 提交于 2020-01-06 05:08:49
问题 I am trying to forward declare a templated class A<T> for use in a class Visitor . It would suffice for my purposes to declare the int instance A<int> of the class A . I have tried two approaches but both give different errors, and I don't know how to proceed. Here is a MWE of my error: namespace visitor{ class Visitor{ public: virtual void visit(nsp::A<int>*) = 0; }; } namespace nsp{ template <class T> class A{ A(); T t_attribute; void accept(visitor::Visitor*); }; void A<int>::accept