Homogenous Variadic Functions - A Lightning-Library Approach in ~11.54 sec/LOC - Tobias Loew

preview_player
Показать описание
#Boost #Cpp #CppNow
CppNow Twitter: @CppNow
------
Tobias Loew
------

May 1, 2022 - May 6, 2022 - Aspen, Colorado
-------------------------
---

*--*

---
Рекомендации по теме
Комментарии
Автор

nice but in my code i'd prefer using only explicit conversions

sTammoi
Автор

Maybe:
template <typename T>
concept ints_only = std::same_as<T, int>;

void foo(ints_only auto&&... args);

au._.
Автор

or you could've provided a template type for comparison:

template<typename T, typename... Args>
concept HomogeniousArgPack = (std::is_convertible<T, Args>::value && ...);

template<typename T, typename... Args>
requires HomogeniousArgPack<T, Args...>
T foo(const Args&... args); // specify the type manually (foo<int>(...)), or
T foo(const T& first, const Args&... rest); // let the first argument specify the type

P.S.: now we can overload these functions to a specific type:

template<typename... Args>
float foo<float, Args...>(const float& first, const Args&... rest);


now if we call foo with floats, it would trigger the overloaded function

Raspredval