Skip to content

Commit 04d77d2

Browse files
committed
Switched implementation of P0315Visitor from std::variant to compile-time based approach.
1 parent c91665f commit 04d77d2

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

InsightsHelpers.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,18 +1619,17 @@ struct overloaded : Ts...
16191619
};
16201620
template<class... Ts>
16211621
overloaded(Ts...) -> overloaded<Ts...>;
1622+
//-----------------------------------------------------------------------------
16221623

1623-
bool P0315Visitor::VisitLambdaExpr(const LambdaExpr* expr)
1624+
void P0315Visitor_HandleLambdaExpr(OutputFormatHelper& ofm, const LambdaExpr* expr)
16241625
{
1625-
mLambdaExpr = expr;
1626-
1627-
std::visit(overloaded{
1628-
[&](OutputFormatHelper& ofm) { ofm.Append(GetLambdaName(*expr)); },
1629-
[&](CodeGenerator& cg) { cg.InsertArg(expr); },
1630-
},
1631-
mConsumer);
1626+
ofm.Append(GetLambdaName(*expr));
1627+
}
1628+
//-----------------------------------------------------------------------------
16321629

1633-
return false;
1630+
void P0315Visitor_HandleLambdaExpr(CodeGenerator& cg, const LambdaExpr* expr)
1631+
{
1632+
cg.InsertArg(expr);
16341633
}
16351634
//-----------------------------------------------------------------------------
16361635

InsightsHelpers.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <functional>
1818
#include <optional>
1919
#include <string>
20-
#include <variant>
2120

2221
#include "InsightsStrongTypes.h"
2322
#include "StackList.h"
@@ -355,25 +354,32 @@ is(T) -> is<T>;
355354
const DeclRefExpr* FindDeclRef(const Stmt* stmt);
356355
//-----------------------------------------------------------------------------
357356

357+
void P0315Visitor_HandleLambdaExpr(class OutputFormatHelper&, const LambdaExpr*);
358+
void P0315Visitor_HandleLambdaExpr(class CodeGenerator&, const LambdaExpr*);
359+
//-----------------------------------------------------------------------------
360+
358361
///! Find a LambdaExpr inside a Decltype
359-
class P0315Visitor : public RecursiveASTVisitor<P0315Visitor>
362+
template<typename T>
363+
requires(std::derived_from<T, CodeGenerator> or std::same_as<T, OutputFormatHelper>)
364+
class P0315Visitor : public RecursiveASTVisitor<P0315Visitor<T>>
360365
{
361-
std::variant<std::reference_wrapper<class OutputFormatHelper>, std::reference_wrapper<class CodeGenerator>>
362-
mConsumer;
366+
T& mConsumer;
363367
const LambdaExpr* mLambdaExpr{};
364368

365369
public:
366-
P0315Visitor(class OutputFormatHelper& ofm)
367-
: mConsumer{ofm}
370+
constexpr P0315Visitor(T& consumer)
371+
: mConsumer{consumer}
368372
{
369373
}
370374

371-
P0315Visitor(class CodeGenerator& cg)
372-
: mConsumer{cg}
375+
bool VisitLambdaExpr(const LambdaExpr* expr)
373376
{
374-
}
377+
mLambdaExpr = expr;
378+
379+
P0315Visitor_HandleLambdaExpr(mConsumer, expr);
375380

376-
bool VisitLambdaExpr(const LambdaExpr* expr);
381+
return false;
382+
}
377383

378384
const LambdaExpr* Get() const { return mLambdaExpr; }
379385
};

0 commit comments

Comments
 (0)