« first day (1602 days earlier)      last day (1242 days later) » 

8:14 AM
I am trying to make a single template based visitor class for an AST. I want to have two types of visitors: one that accepts references in visit method and another that accepts const references in the visit method. Is there a neat way to do this?
class BaseVisitorMutable {
public:
    void visit(SomeType&);
    void visit(SomeOtherType&);
};

class BaseVisitorConst {
public:
    void visit(const SomeType&);
    void visit(const SomeOtherType&);
};
This method duplicates the code twice just for the sake of a const qualifier. I was thinking of some template sorcery (like add_const_if<bool>). Is there a better way to do this?
 
 
2 hours later…
9:51 AM
@Yashas Why not just have it as a template? So, that you have void visit(T someType)? If you need different code paths you can use std::is_const from type traits?
@Yashas Take a look a this method: stackoverflow.com/a/39510711/314290
 
10:27 AM
@Mikhail it's a base class; I actually meant void visit(...) = 0; in the example posted.
 
 
5 hours later…
3:19 PM
how to std::visit on a multiple variants simultaneously? I want something like this: std::visit([] (auto arg1, auto arg2) { /* ... */ }, variant1, variant2);
std::visit already supports it! Yay!
 
3:42 PM
@Yashas yeah it basically just makes a large if/else chain internally and then calls the right one
 

« first day (1602 days earlier)      last day (1242 days later) »