template-specialization

Need to understand function template resolution rules

£可爱£侵袭症+ 提交于 2019-12-24 12:13:23
问题 I'm really confused by certain details of template overloading/specialization resolution rules. I tried to get some understanding on the subject by going through this article by Herb Sutter on template overloading/specialization. I'm stuck on the following specific point in the article. Here it is Consider the following code: // Example 2: Explicit specialization // template<class T> // (a) a base template void f( T ); template<class T> // (b) a second base template, overloads (a) void f( T*

Class member function template partial specialization with variadic parameters [closed]

限于喜欢 提交于 2019-12-24 10:27:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm using Visual Studio 2017 CE version 15.6.2 with compiler language options set to: ISO C++ Latest Draft Standard (/std:c++latest) I'm working with a majority of the functions from <random> and I have 2 classes that are non template classes, RandomEngine and RandomDistribution . These classes can not be

Function Template Specialization on Function Pointers

China☆狼群 提交于 2019-12-24 02:56:22
问题 I have a sanitization function that I want to run on (traditional) pointer types only. My problem is with function templates I can get as far as limiting the function to only pointers, however because of casting rule differences between function pointers and regular pointers, I run into problems. The Sanitize() function needs to run against a whole slew of types, some of which are pointers and need to be sanitized, others of which are function pointers of varying arity and parameter types and

Use of enable_if to match only classes which have a certain static data member, and that has only specific values

最后都变了- 提交于 2019-12-24 01:03:11
问题 I want to specialize a function for a subset of classes which: have a certain static data member variable, and such variable has only certain possible values. The code below illustrates the intent, but it does not compile unless I comment out the lines related to the B classes in main . This is because code is not a member of the Bx classes, but the enable_if condition is valid if the template argument has a code member variables. How should I modify it? Unfortunately I work with very old

specialize a template class using a nested name specifier of another template class

浪子不回头ぞ 提交于 2019-12-23 22:53:55
问题 I want to specialize a template class using a nested name specifier of another template class. But the compiler complains that it can't deduce this code. What should I do? template <typename T> struct convert{ // this is a class in an extern library // the guide of this library tells me to specialize // convert to my own class for some features. void foo(T&t) {/* do something */} }; template <typename T> struct A{ struct A_sub{ // my class }; }; template <typename T> struct convert<A<T>::A

Clang can't handle a template specialization using referenced template template, but GCC can

点点圈 提交于 2019-12-23 15:43:39
问题 I use a pattern like the following in my generic architecture. It compiles and runs correctly in GCC 5.2.0: #include <iostream> using namespace std; template<class Baz> class Foo { public: void foo(){cout<<"Foo method";} }; template<template<class> class FooType> class BarBase: public FooType<int> { public: double bar() {cout<<"Generic bar";} }; template<template<class> class FooType> class Bar: public BarBase<FooType> { }; template<> class Bar<Foo>: public BarBase<Foo> { public: void

Function specialized with template

对着背影说爱祢 提交于 2019-12-23 10:08:50
问题 I need to make a specialization of my function with template class and have problem with "illegal use of explicit template arguments". template <typename T> class MyClass { /* ... */ }; // it can be any template class, eg std::vector template <typename T> void foo() { /* ... */ } // my template function which need a specialization template<> void foo<int>() /* sth special for integers - it works */ } template<template T> void foo<MyClass<T> >() /* sth special for template class with any

C++ explicit template specialization of templated constructor of templated class

本秂侑毒 提交于 2019-12-23 09:47:09
问题 I have a class like template <class T> struct A{ template <class U> A(U u); }; I would like to write an explicit specialization of this for a declaration like A<int>::A(float); In the following test code, if I comment out the specialization, it compiles with g++. Otherwise, it says I have the wrong number of template parameters: #include <iostream> template <class T> struct A{ template <class U> A(T t, U *u){ *u += U(t); } }; template <> template <> A<int>::A<int,float>(int t, float *u){ *u +

C++ explicit template specialization of templated constructor of templated class

て烟熏妆下的殇ゞ 提交于 2019-12-23 09:46:34
问题 I have a class like template <class T> struct A{ template <class U> A(U u); }; I would like to write an explicit specialization of this for a declaration like A<int>::A(float); In the following test code, if I comment out the specialization, it compiles with g++. Otherwise, it says I have the wrong number of template parameters: #include <iostream> template <class T> struct A{ template <class U> A(T t, U *u){ *u += U(t); } }; template <> template <> A<int>::A<int,float>(int t, float *u){ *u +

Code duplication and template specialization (when the specialized function has different return types)

こ雲淡風輕ζ 提交于 2019-12-23 09:16:57
问题 I am creating a templated class D<N> , with a method (operator(), in this case) that returns different types, depending on the value of N. I could only make this work by creating two separate class declarations, but this came at the cost of a lot of code duplication. I also tried to create a common base class to throw the common stuff into, but I couldn't get the constructor to inherit right and don't know how idiomatic that would be as well... #include <cstdio> template <int N> struct D{ int