791 questions
1
vote
1
answer
78
views
Implementation of the (modular) visitor design pattern
I am creating a QueryBuilder, so I though that it w'd be amazing to serialize objects to tokens, and have an AST within the QueryBuilder. So I immediatly though about the Visitor Design Pattern.
Here'...
3
votes
1
answer
184
views
Using CRTP pattern implement an inheritable visitor
I'm trying to implement an inheritable visitor method for a class using CRTP instead of a virtual function. First we have some code like this:
#include <iostream>
#include <memory>
struct ...
3
votes
2
answers
195
views
Problem with satisfying a C++ concept in a std::visit
I've a C++ concept where I need to check that the class has a particular public attribute.
My problem is that the concept works if I use it directly, but fails if I use it in std::visit.
This is the ...
1
vote
1
answer
109
views
Is using a visitor with an empty interface storage a reasonable way to expose implementation-specific metrics in a C++ API?
I’m designing a C++ API where:
Clients only ever use a main trait interface (main_trait).
Each concrete main_trait implementation has a dedicated metrics interface (metrics_trait) exposing runtime ...
0
votes
2
answers
159
views
cannot use static_assert for unsupported type
I'm trying to use code as below, but I am getting compilation errors.
The goal here is to have the "unsupported type in visitor triggered at compile time when a D is passed to visitor. Can ...
0
votes
3
answers
131
views
Visit variant of nested classes : how to avoid redundant code?
I have a lot of polymorphic classes. Each of them has a nested class named Configuration containing all the hyperparameters required by the class. For each class tree, I create a variant of the ...
2
votes
1
answer
89
views
Is it mandatory for the visit methods to return void in the Visitor Pattern?
This is the Java example of the visitor pattern in wikipedia:
These two interfaces are at the core of the pattern:
interface CarElement {
void accept(CarElementVisitor visitor);
}
interface ...
2
votes
1
answer
66
views
Is it possible to call templated functions in templated derived classes from a pointer to base?
I have a type erased container for holding various classes that meet certain simple requirements. The goal is to provide a consistent interface for similar data-container classes that would then allow ...
0
votes
1
answer
65
views
Defining and blanket implementing a common trait to avoid dependencies in Rust
I have various generic containers defined in many different crates using a common declarative macro. Each looks something like:
struct Container1<T> {
a: T,
b: T,
}
On the other hand, I ...
0
votes
0
answers
150
views
Using Composite and Visitor pattern to render a OpenGL scenegraph
I'm trying to implement a Open GL (4.6) setup with the Composite pattern (for a scene graph with Node, Cube and TransformNode classes) and the Visitor pattern (with a DrawVisitor to handle rendenring)....
1
vote
2
answers
135
views
C++ Visitor Pattern with Variant Return Type and Accumulated State
I am trying to build computations against a well defined set of types, much like you would get in a database or dataframe computation library. Given the types are limited but the algorithms are ...
0
votes
1
answer
155
views
Combining Command and Visitor design patterns
Designing the architecture of a personal project, I've come up with the idea of using the combination of these two patterns to solve an architectural issue. In an MVC context, I need to implement ...
1
vote
2
answers
434
views
How to visit on multiple variants with restricted to same type
I have a question about using a generic visitor with exclusion of non-equal types. Suppose I have the following:
using StorageT = std::variant<std::vector<int>, std::vector<double>>;
...
0
votes
1
answer
110
views
C++: Least painful way to write a Visitor to use in apply std::visit for a templated function?
I'm using a heavily templated library with a function that has multiple template arguments. I'd like to create a dynamic wrapper for this function by creating a class whose members will be the ...
3
votes
3
answers
698
views
Visitor Pattern with Different Return Types for each Node Visited
I am attempting to implement the Visitor design pattern.
I have a basic understanding of the Visitor pattern and its classic implementation.
I am attempting to morph the visitor pattern to meet my ...
0
votes
1
answer
67
views
Trouble with ANTLR Visitor Pattern - Not Entering visitExpressFrag Method
I am working on a lexical and syntax analyser that I amimplementing semantic analysis and intermediate representation generation using ANTLR, and I've encountered a problem with my visitor ...
1
vote
1
answer
90
views
Kotlin sequence yield in a visitor closure
I'm trying to use yield in a sequence to lazily emit items from a visitor but I'm getting the error "Suspension functions can be called only within coroutine body".
I'm not trying to suspend ...
0
votes
0
answers
106
views
Visitor pattern serialization memory bloat
I'm working on a serialization library for an embedded target. The library is based on a classic visitor pattern with a templated pack() method implemented in each struct that I want to serialize. ...
0
votes
1
answer
126
views
Persistent config with visitor pattern and static memory allocation
I'm preparing a persistent config module for an embedded project. I want to use serialization implemented using the visitor pattern:
struct softwareInfo
{
uint32_t version;
std::array<...
2
votes
1
answer
89
views
Why can't std::visit disambiguate templated overloads
I'm trying to build a command pattern where each command has access to a defined interface. Receivers implement one or more of these interfaces and can then have commands, by way of CommandLists ...
0
votes
1
answer
415
views
Visitor Pattern with templates for traversing tree structure
I got a "tree" like structure that represents a simple addition expression. (ex 2 + 4 + (3 + 5))
I'm using the visitor pattern to traverse the tree and find the sum. The problem is that I ...
0
votes
1
answer
110
views
Is there a way to implement trait objects with generic functions?
Basically I am trying to implement visitors-coding paradigm, where Expr trait needs to be implemented by Binary struct. I want to use Expr as a trait object. Any entity wanting to interact with Expr ...
1
vote
1
answer
1k
views
No matching function call to std::visit() using overload pattern
I'm trying to dispatch a variant inside a variant with the visitor overload pattern. However I can't seem to fit the parameters to what is expected. I get this (truncated, for more output see compiler ...
1
vote
2
answers
182
views
Visitor design pattern: can my visitor returns a Promise or should I create a new interface
I am now using a Visitor pattern where I have 2 visitors using the same interface returning T. It basically looks like the schema below, but my visitor returns something.
I would like to change the ...
-1
votes
1
answer
129
views
C# - Can't use double-dispatch Visitor for array of derived generic types
I wanted to know why I can't get running any Visitor of generic objects in C#.
For some reason the program always picks the least concrete generic overload of my generic.
P.S.: I'm not after ...
1
vote
6
answers
1k
views
How do I make my method return different types of list base on the input type of list?
I want to create a mapping from input List<T> to outputList<S>, for the method named foo(List<T>), but in a "smart" way . The way foo(List<T>) processes different ...
1
vote
1
answer
149
views
Ada visitor design pattern and generics
I'm implementing a visitor pattern and I have some elements that I could implement using generics, but the GNAT compiler complains with the generic type.
I have a solution using generic mix-ins but ...
1
vote
0
answers
76
views
Is it possible to merge AST transform visitors consistently?
Given two visitors A and B that sequentially apply transformations to a given AST, is it always possible to automatically merge A and B into a single visitor that, by applying A and B node by node, ...
-1
votes
1
answer
146
views
c++ iterate multiple ordered collections of different types
Are there any parts of the standard library that would support the following use case:
You have N collections, with each collection potentially being a type of collection (C1, C2 ..., Cn) all of which ...
0
votes
2
answers
144
views
Visitor Pattern Error(use undefined type)
I am studying visiting patterns. However, the following error occurs. not defined.
The cat class only has its own name and age.
agevisitor and namevisitor, which inherit Visitor interface, output age ...
1
vote
1
answer
614
views
run std::visit on the variant and original type
Have a strange case where sometimes a function takes a variant but other times it takes the member of the variant.
void branching_function(auto argument)
{
using typer = std::remove_reference<...
0
votes
0
answers
48
views
How can I provide subclass-specific methods to call on an instance of baseclass?
Trivially, if I have a base-class and several sub-classes which all implement the same method signature, I can do the following:
abstract class BaseClass
{
public abstract int GetValue();
}
class ...
0
votes
2
answers
286
views
How to support two visitors which returns different return value types in Rust?
I am trying to implement a Visitor pattern in Rust.
I am not able to find a way to support two visitors which return different return value types.
Playground link
trait Visited<R> {
fn ...
5
votes
0
answers
976
views
Acyclic Visitor Pattern: is it actually inferior to the original Visitor pattern?
I have read several articles and answers about the merits of the Acyclic Visitor pattern over the original Visitor pattern. To avoid ambiguity, I refer to the Acyclic Visitor as described in this ...
0
votes
1
answer
142
views
How do I visit a constant term in antlr4 with c++?
I have a grammar that at some point has the following rule:
boolConst :
'true'
| 'false';
This leads to the following code (with visitor activated) being generated:
class ...
0
votes
0
answers
94
views
Typescript Visitor Pattern missing type info
I seem to be losing type info using the visitor design pattern in typescript:
abstract class AbsVisitor
{
public abstract visitPerson(p: Person): void;
public abstract visitAddress(p: Address): ...
2
votes
2
answers
665
views
Visitor Pattern with Templated Visitor
This is a follow up on No user defined conversion when using standard variants and visitor pattern
I need to implement a templated version of the visitor pattern as shown below, however it looks like ...
2
votes
2
answers
525
views
No user defined conversion when using standard variants and visitor pattern
Could you please help me figure out why is this not working i.e. refering to the comment in the code //I need to do this but I can't. I thought this the goal!? I have no idea why this is not working, ...
1
vote
1
answer
148
views
Rascal MPL print id of all traversed nodes in a visit
Is it possible to print all node ids / values that are traversed in a visit? Take the following code sample:
top-down visit(asts) {
case x: println(typeOf(x));
}
I now get all types of the nodes ...
0
votes
2
answers
497
views
Using visitor pattern without writing too many overloads
I have two datatypes called DragonVector and UnbiasedDragon and I am using visitor pattern for dynamic type inference.
I want to extend a DragonVector only by a DragonVector and similarly for ...
0
votes
0
answers
33
views
Errors with forward declarations in cpp
I am trying to use a visitor 'BehaviorVisitor' which has a method for each type of 'Flower' such as 'Sunflower'. I keep getting this error from BehaviorVisitor:
error: variable has incomplete type '...
0
votes
0
answers
151
views
How to iterate through an xml file if only the root node is provided
In a complex C++ program, which is using Xerces, I have to iterate through XML files, and I have to modify its tags.
One of the simpliest XML file looks like this:
<?xml version="1.0" ...
-1
votes
1
answer
128
views
Antlr4 generated java code visitor pattern confusion
When antlr generates java code for visitor pattern, we get a base visitor class.
public class YxBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements YxVisitor<T> {
/**
...
3
votes
0
answers
78
views
call non-virtual method of derived class in polymorphic hierarchy of library that can't be modified without down-casting
Today interviewer told me that Visitor pattern & double dispatch can be used to call non-virtual method of derived class from 3rd party library which source code can't be accessed/changed (this is ...
0
votes
2
answers
365
views
How to avoid empty visit functions in visitor pattern?
I have the following use case. I have a restriction interface that needs to fill its members from dependencies, do the validations. These methods are applicable for all implementations and hence it is ...
1
vote
1
answer
300
views
How to iterate over mixed interface implementation array?
I have the following classes.
interface interface1() {
void function1()
}
interface interface2 extends interface1() {
void function2()
}
class implementation1 implements interface1 () {
@...
1
vote
0
answers
591
views
Visitor Pattern implementation in Python
I am doing some research on the Visitor Design Pattern implementations in Python and came across an interesting version which I see a lot of potential to use in real world scenarios but it also ...
0
votes
1
answer
180
views
C++ Extend Smart pointers so that they can also be used for substitution
I have been writing a pet programming language using c++. I've mostly settled on using a Visitor Design Pattern to interreact with my AST. The interactions I'll need is some codegen, and various ways ...
-1
votes
2
answers
248
views
Decorator pattern log each before and after
I want to log each iteration of my text changes nevertheless not sure what should be the proper way of doing that. See below. The first test is GeeksforGeeks and last one will be <i><u><...
1
vote
1
answer
490
views
std::visit Vs For_each loop
Let the data structure be anything (Array, Vectors, Std::Variant). But what is the difference in traversing using just for/for_each against std::visit.
for (auto& Element: collection){
std:...