How to handle template class static members and storage in situations where leaving to static cleanup isn't desired

Advertisements I’ve recently gotten back into C++ after many years in C# and java land, and am loving where C++ has gone in my absence (since pre C++11, am now soaking up C++20!). The power of templates is really exciting to me. However, I quickly ran into something that seems impossible to deal with. I’ve… Read More How to handle template class static members and storage in situations where leaving to static cleanup isn't desired

variadic template 'ambiguous call to overloaded function' seems a false error

Advertisements I try to write a template function to initialize given systems and run the app and at the end run shutdown function on initialized systems. This code should work in my eye and intellisense doesn’t give any error but compiler: 1>C:\VisualStudio\DirectApp\AppMain.cpp(32,2): error C2668: ‘initialize_these’: ambiguous call to overloaded function 1>C:\VisualStudio\DirectApp\AppMain.cpp(28,13): message : could be… Read More variadic template 'ambiguous call to overloaded function' seems a false error

Why is the const lost in an expression like `const T&` where T is an rvalue reference?

Advertisements I’m working on a templated class, and given an incoming type T the template needs to map to a "safe" const reference. (This is essentially to avoid handing the ability to mutate to a wrapped function when it’s called; see here for the real code). The original author wrote something equivalent to this: template… Read More Why is the const lost in an expression like `const T&` where T is an rvalue reference?

Why can't I std::apply for a member function

Advertisements I’m trying to develop a wrapper to help people use pthread on calling any member function. template <typename> struct signature; template <typename C, typename R, typename… Args> struct signature<R (C::*)(Args…)> { using return_type = R; using pure_argument_type = std::tuple<C*, std::tuple<Args…>>; // obj, {args…} using argument_type = std::tuple<R (C::*)(Args…), pure_argument_type>; // obj.mem_fn, {obj, args…} };… Read More Why can't I std::apply for a member function

Can you detect template member of a class using std::is_detected

Advertisements I use std::experimental::is_detected to determine if class has certain member functions: #include <utility> #include <experimental/type_traits> template<typename USC> class Descriptor { private: template<class T> using has_member1_t = decltype(std::declval<T>().member1(std::declval<std::vector<char> &>())); public: static constexpr bool has_member1 = std::experimental::is_detected_convertible_v<long long, has_member1_t, USC>; }; The problem is I also need to determine if class has certain template member function… Read More Can you detect template member of a class using std::is_detected