C++Now 2017: Vittorio Romeo “You must type it three times”

CppNow · 5K views · 2017 · 5:13

Open on YouTube

C, C++, Rust, Go & systems languagesProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining how to alias or wrap overloaded and variadic template functions correctly, since the full forwarding wrapper needs the body repeated three times.

Recommended by 1 people across 1 different months, 2012 to 2020.

What it is

A five-minute lightning talk from C++Now 2017 by Vittorio Romeo. It covers the C++ idiom of writing a function body three times (noexcept, decltype return type, and the body itself) to build SFINAE-friendly, noexcept-correct wrapper functions that forward to overloaded or templated functions.

What people said

Recommends 463035818_is_not_an_ai · 2020-10 · Stack Overflow · on “Allow function of variadic argument count as template function argument”

@Reizo I wrote "For the sake of brevity I ommitted forwarding and storing th....". To get it fully right even more is needed: [this video] .

Cites alfC · 2012-12 · Stack Overflow · on “What is the best way of renaming (alias/forward) a function in C++?”

(I'll restrict this question to C++11, since I believe there is no general way to do this in C++98). Supposed I have a complicated (in terms of signature) set of template functions and/or overloaded functions, and I want to use these functions in the exact same way but using a different name (that is, an alias). For example: template<class A, class B, class C> D fun(A a, B& b, C&& c){ ... } template<class E, class F> G fun(H<E> he, F& f){ ... } ... many other versions of fun Now suppose that I want to rename (or alias , or forward to be more precise) these functions, all at once (i.e. be able to use a different name for the same function without rewriting it). Such that, in other parts of th

Cites Vittorio Romeo · 2017-09 · Stack Overflow · on “Constexpr alias of overloaded template function”

std::make_shared [LINK] is a variadic function template . You are only specifying <foo> as a template parameter, but you would also need an int somewhere in there. Regardless, your approach is bound to fail as it's reliant on how make_shared 's template arguments were laid out and because it's generally cumbersome to work with overload sets in C++. What I suggest is to create a wrapper function instead: constexpr auto newfoo(int x) { return std::make_shared<foo>(x); } In my opinion it is easier to write, read, and understand. If you really need SFINAE-friendliness and noexcept , you can repeat the body three times [this video] : constexpr auto newfoo(int x) -> decltype(std::make_shared<foo>(x)) n