Is there a reason to use std::conjunction/std::disjunction instead of a fold expression over “&&”/”||”?

std::conjunction short-circuits ::value instantiation, while the fold expression doesn’t. This means that, given: template <typename T> struct valid_except_void : std::false_type { }; template <> struct valid_except_void<void> { }; The following will compile: template <typename… Ts> constexpr auto test = std::conjunction_v<valid_except_void<Ts>…>; constexpr auto inst = test<int, void>; But the following won’t: template <typename… Ts> constexpr auto … Read more

details of std::make_index_sequence and std::index_sequence

I see sample code around there, but I really want a dumbed down step by step explanation of how an index_sequence is coded and the meta programming principal in question for each stage. What you ask isn’t exactly trivial to explain… Well… std::index_sequence itself is very simple: is defined as follows template<std::size_t… Ints> using index_sequence … Read more

Confusing templates in C++17 example of std::visit

What are the two lines declaring overloaded, just above int main(), mean? The first one template<class… Ts> struct overloaded : Ts… { using Ts::operator()…; }; is a classic class/struct declaration/definition/implementation. Valid from C++11 (because use variadic templates). In this case, overloaded inherits from all template parameters and enables (using row) all inherited operator(). This is … Read more

generic member function pointer as a template parameter

You could try something like this: template <typename T, typename R, typename …Args> R proxycall(T & obj, R (T::*mf)(Args…), Args &&… args) { return (obj.*mf)(std::forward<Args>(args)…); } Usage: proxycall(obj, &hello::f); Alternatively, to make the PTMF into a template argument, try specialization: template <typename T, T> struct proxy; template <typename T, typename R, typename …Args, R (T::*mf)(Args…)> … Read more

Simulate variadic templates in C#

C# generics are not the same as C++ templates. C++ templates are expanded compiletime and can be used recursively with variadic template arguments. The C++ template expansion is actually Turing Complete, so there is no theoretically limit to what can be done in templates. C# generics are compiled directly, with an empty “placeholder” for the … Read more

Understanding the overhead of lambda functions in C++11

The problem here is your usage of std::function. You send it by copy and therefore copying its contents (and doing that recursively as you unwind parameters). Now, for pointer to function, contents is, well, just pointer to function. For lambda, contents are at least pointer to function + reference that you captured. This is twice … Read more

How to reverse the order of arguments of a variadic template function?

Overall approach and usage The overal approach consists in packing the arguments into an std::tuple of references, exploiting the perfect forwarding machinery of std::forward_as_tuple(). This means that, at run-time, you should incur in very small overhead and no unnecessary copy/move operations. Also, the framework does not use recursion (apart from compile-time recursion, which is unavoidable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)