How do I get the return type of a member function without an object?
You don’t need that- remember that since decltype doesn’t evaluate its argument, you can just call on nullptr. decltype(((T*)nullptr)->foo()) footype;
You don’t need that- remember that since decltype doesn’t evaluate its argument, you can just call on nullptr. decltype(((T*)nullptr)->foo()) footype;
There is no way to explicitly specify the template arguments when calling a constructor template, so they have to be deduced through argument deduction. This is because if you say: Foo<int> f = Foo<int>(); The <int> is the template argument list for the type Foo, not for its constructor. There’s nowhere for the constructor template’s … Read more
To figure out the problem let separate statements: auto f = bind(&TestA::testa, &testA, _1, _2); // OK test.setCallback(f); // <<— Error is here setCallback needs to know type of T and it can’t deduce it from f, so give it a type test.setCallback<TYPE>(f); // TYPE: int, float, a class, …
Neither GCC nor Clang is a linker, and ICF needs to be done by the linker, or at least with cooperation with the linker. Edit: They don’t do ICF, so yes, distinct instantiations produce distinct code. The GNU gold linker supports ICF with the –icf option, which needs the GCC option -ffunction-sections to be used. … Read more
extern template class A<long>; This line says that A<long> is to be explicitly instantiated according to the definitions the compiler has already seen. When you add a specialization later, you break that meaning. Add a declaration of your specialization to the header file. template <typename T> struct A { /*…*/ }; template<> int A<long>::get() const; … Read more
You are actually attempting the impossible. The very heart of the matter is simple: virtual and template do not mix well. template is about compile-time code generation. You can think of it as some kind of type-aware macros + a few sprinkled tricks for meta programming. virtual is about runtime decision, and this require some … Read more
The right way for a template function to accept any std::vector by const& is: template<typename T, typename A> void some_func( std::vector<T,A> const& vec ) { } the second argument is the “allocator”, and in some advanced usage of std::vector it will not be the default one. If you just accept std::vector<T>, your some_func will reject … Read more
You have two choices here — the first is the way you did it — simply add the appropriate markup into a template (or a block if you want to be able to override it in templates which extend your first template.) The second way is to use Jinja2’s include function: {% block javascript %} … Read more
This syntax is slightly different. First, because types are easier to work with than packs, a type that holds a pack. The using type=types; just saves me work in the code that generates a types: template<class…>struct types{using type=types;}; Here is the workhorse. It takes a signature, and produces a types<?…> bundle containing the arguments for … Read more
You could refactor or wrap f to return a new X instead of having it passed, since this would play pack expansion into the hand and make the function really concise: template<class T> X fw(T const& t){ X x; f(x, t); return x; } template<class… Args> void h(Args… args){ X xs[] = { fw(args)… }; … Read more