Cppnow2017
Repository for my C++Now 2017 talks.
Install / Use
/learn @vittorioromeo/Cppnow2017README
cppnow2017
Repository for my C++Now 2017 talks.
Implementing variant visitation using lambdas
The addition of
std::variantto the upcoming C++17 standard will introduce a "type-safe sum type" to the Standard Library. Variants model a "choice between types" - they essentially are type-safe "tagged unions".The interface they expose, however, is often more cumbersome to use than it needs to be: defining exhaustive visitors requires the user to create a class with several
operator()overloads, or to create a chain of >if constexpr(...)calls. Both solutions are not very elegant.After a brief overview of
std::variantand its usefulness, this talk will focus on the implementation of a "lambda-based in-place visitation" approach, where the user can visit a variant by simply providing a set > of lambdas on the spot. This will require implementing a way of overloading arbitrary function objects.Recursive variant types will then be covered and the "lambda-based" visitation techniques will be applied to them. This will require implementing the "Y combinator" higher-order function to achieve > zero-runtime-overhead lambda recursion.
This talk is intended for developers familiar with C++11 and C++14 core language features (lambdas, variadic templates,
auto, etc...). Prior knowledge ofstd::variantor sum types is not required.
-
~YouTube Video~ (not yet available)
You must type it three times
Lightning talk about the fact that code has to be manually copy-pasted three times to achieve noexcept-friendliness and SFINAE-friendliness. E.g.
template <typename F, typename... Ts>
auto log_and_call(F&& f, Ts&&... xs)
noexcept(noexcept(
std::forward<F>(f)(std::forward<Ts>(xs)...)
))
-> decltype(
std::forward<F>(f)(std::forward<Ts>(xs)...)
)
{
log << "calling `f`\n";
return std::forward<F>(f)(std::forward<Ts>(xs)...);
}
- ~YouTube Video~ (not yet available)
Related Skills
node-connect
348.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
Security Score
Audited on Jul 15, 2021
