Questions tagged [partial-specialization]

Partial template specialization is a particular form of class template specialization. Usually used in reference to the C++ programming language, it allows the programmer to specialize only some arguments of a class template, as opposed to explicit specialization, where all the template arguments are provided.

316 questions
1
vote
2 answers

Partial specialization of type parameter in template class with type & template template parameters

I want to specialize the type parameter of the following template class, which has a type parameter and a template template parameter: template < typename T, template class Foo > class Bar; I tried every permutation of adding…
CodeBricks
  • 1,771
  • 3
  • 17
  • 37
1
vote
5 answers

partial specialization with inheritance. Can I avoid inheritance?

I am writing a vector class and I would like it to have the following characteristics: Use static allocation on the stack whenever possible (to avoid calling new for efficiency). Be able to be instantiated from a pointer if the user prefers to…
Alejandro
  • 1,064
  • 1
  • 8
  • 22
1
vote
1 answer

C++ Typedef in Partial Template Instantiation

I'm having trouble figuring out why my partially instantiated template isn't compiling in C++. I'm trying to provide a class that returns different types based on the templates that are passed to it: enum EVectorType { eVectorType_Scalar, …
Mokosha
  • 2,737
  • 16
  • 33
1
vote
1 answer

C++ Template Specialization: compile error: "is not a type"

If I remove the template specialization part (the one that tries to print "Test 2"), the code compiles fine, but I'd like to be able to have a special case that runs a different code path that looks clean to outside users. #include using…
1
vote
1 answer

Can you partially specialise a template for a template type that has non-type parameters

I think the easiest way to ask this question is by first giving the code example (I've made it available on ideone as well: http://ideone.com/OjK2sk): template struct BoundInt { static…
Timma
  • 663
  • 7
  • 19
1
vote
1 answer

Effective use of enable_if with C++ templates to avoid class specialization

I am having trouble getting my code to compile. clang, g++ and icpc all give different error messages, A bit of background before getting to the question itself: I am working now on a template class hierarchy for working with Matrices. There are…
1
vote
2 answers

partial specialization with dependent name (typename)

I have the following simple strinToTypeImpl function which converts any kind of string into the template type. The problem I am concerned about is the fact that the compiler tells me for the partial specialization for typename MyMatrix::Vector3 …
Gabriel
  • 8,990
  • 6
  • 57
  • 101
1
vote
1 answer

C++ partial specialization within the inheritance statement?

So I got myself in a pickle with C++ templates. Assuming I got a hierarchy of container-like classes of the form: template class AContainer{ // ... }; And through inheritance different containers with different internal…
1
vote
2 answers

Understanding partial specialization of inherited nested class templates

This question is connected to a previous Q&A in which a bug report for gcc was mentioned (supposedly fixed in gcc 4.5.0) and concerns some peculiarities for partial specialization of nested class template. My setup is that I have a class Base with…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
1
vote
2 answers

Can I create a partial template specialization of of a class template matching enumeration types?

I have a function template powered by a set of class template explicit specializations giving syntax like abc.GetAs("Name"); (where GetAs is something like: template T GetAs(wchar_t const* propName) const { typedef…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
1
vote
3 answers

C++ template specialization via a base class

I want to be able to make the compiler shout when i call a constructor of foo with a class that is NOT derived from _base*. The current code allows only for foo<_base*> itself. Any easy solution ? class _base { public: // ... }; class…
Roman Pfneudl
  • 707
  • 1
  • 8
  • 21
1
vote
3 answers

How To Convert Templated Function Overloads to Partial-Specialized Templated Class Static Methods?

I have several functions that I want to specialize based on type qualities, such as "character, signed-integer, unsigned-integer, floating-point, pointer"; using type_traits seems like the way to do this, and have code similar to the to the…
1
vote
1 answer

Generic algorithm for calling print on each element in the collection

When writing a template function like: template void print(T const & collection) When looping through the collection and dereferencing the iterator everything works right if you have something like vector unless you change it to…
Blair Davidson
  • 901
  • 12
  • 35
1
vote
1 answer

Partial specialization with a non-template class which is inherited from a template class

Example 1 If we have Base and Derived classes class Base {}; class Derived : public Base {}; and a template class template class Partialy { public: void say() { std::cout << "Partialy Default" <<…
Seagull
  • 3,319
  • 2
  • 31
  • 37
1
vote
1 answer

member-template specialization

template class C { void f() { } }; /*template void C::f() { }*/ template<> void C::f() { } If we remove comment, code will not compile. I know this (and i also know, that we should have partial specialization…
ForEveR
  • 55,233
  • 2
  • 119
  • 133