Why do I get an error trying to call a template member function with an explicit type parameter?

This is due to a really obscure provision of the standard in which if you have a template that tries to access a template function in an object whose type depends on a template argument, you have to use the template keyword in a weird way: this->template f<int>(); This is similar to the weirdness with … Read more

Is it possible to “store” a template parameter pack without expanding it?

Another approach, which is slightly more generic than Ben’s, is as follows: #include <tuple> template <typename… Args> struct variadic_typedef { // this single type represents a collection of types, // as the template arguments it took to define it }; template <typename… Args> struct convert_in_tuple { // base case, nothing special, // just use the … Read more

How does the standard library implement std::swap?

How is std::swap implemented? Yes, the implementation presented in the question is the classic C++03 one. A more modern (C++11) implementation of std::swap looks like this: template<typename T> void swap(T& t1, T& t2) { T temp = std::move(t1); // or T temp(std::move(t1)); t1 = std::move(t2); t2 = std::move(temp); } This is an improvement over the … Read more

C++ static polymorphism (CRTP) and using typedefs from derived classes

derived is incomplete when you use it as a template argument to base in its base classes list. A common workaround is to use a traits class template. Here’s your example, traitsified. This shows how you can use both types and functions from the derived class through the traits. // Declare a base_traits traits class … Read more

How to convert typename T to string in c++ [duplicate]

There is no built-in mechanism for this. typeid(T)::name() can give some info, but the standard does not mandate this string to be human-readable; just that it has to be distinct for each type. (E.x. Microsoft Visual C++ uses human-readable strings; GCC does not.) You can build your own system though. For example, traits-based. Something like … Read more

Nested templates with dependent scope

The compiler told you exactly what to do. Write typename before ptrModel<std::vector<Data> >::Type, like so: typedef typename ptrModel<std::vector<Data> >::Type Type; The reason for this requirement is that the compiler doesn’t at this point know whether ptrModel<std::vector<Data> >::Type describes a member variable or a nested type. It can’t even figure that out by looking at the … Read more

Why is C++ template use not recommended in a space/radiated environment?

Notice that space-compatible (radiation-hardened, aeronautics compliant) computing devices are very expensive (including to launch in space, since their weight exceeds kilograms), and that a single space mission costs perhaps hundred million € or US$. Losing the mission because of software or computer concerns has generally a prohibitive cost so is unacceptable and justifies costly development … Read more

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