partial-specialization Questions

3

Solved

Given I have a template setup to do something on a type such as... template<typename T> class SimpleTemplate { private: T m_obj; public: void operator()() { m_obj.DoSomething(); } }; And...

5

Solved

I know the language specification forbids partial specialization of function template. I would like to know the rationale why it forbids it? Are they not useful? template<typename T, typename U&...

8

How would you do specialization in C#? I'll pose a problem. You have a template type, you have no idea what it is. But you do know if it's derived from XYZ you want to call .alternativeFunc(). A g...
Frivolity asked 2/3, 2009 at 1:23

1

Solved

While creating this answer for another question I came around the following issue. Consider this program (godbolt): #include <variant> #include <iostream> template <typename T> s...

3

Solved

I want to partially specialize an existing template that I cannot change (std::tr1::hash) for a base class and all derived classes. The reason is that I'm using the curiously-recurring template pat...
Renie asked 23/6, 2009 at 14:39

7

Solved

I know that the below code is a partial specialization of a class: template <typename T1, typename T2> class MyClass { … }; // partial specialization: both template parameters have sa...

4

Solved

The following is a simple template partial specialization: // #1 template <typename T, T n1, T n2> struct foo { static const char* scenario() { return "#1 the base template"; } ...

1

Solved

In the next program, struct template A<int> has a specialization A<char>: template <int> struct A { constexpr operator int() { return 1; } }; template <char c> struct A<...
Concertante asked 15/1, 2022 at 9:56

1

template <class A> struct Foo { template <class Bar> constexpr auto a_method(); }; template <class A> template <class Bar> constexpr auto Foo<A>::a_method() { retu...
Scalf asked 11/1, 2022 at 16:31

3

Solved

I'm trying to specialize a struct template for multiple types at once using SFINAE. I know that something like the following works: #include <iostream> template <typename T, typename Ena...
Nereus asked 9/8, 2016 at 20:23

2

Solved

I read something that it might be confusing for the compiler to write template <class T> void calculator<std::complex<T>>::myMin(); but maybe just give it a hint like so? To make...
Gonocyte asked 17/11, 2016 at 10:41

2

Solved

I have a template class A<T> and its specialization for integral arguments. And both the class and its specialization declare the method foo(), which I would like to define outside of class b...
Orcutt asked 30/7, 2021 at 10:20

1

Solved

I'm trying to define member functions of partially specialized class templates, but different compilers have wildly different opinions of what I'm allowed to do and why. Let's take this slowly and ...

3

Solved

I have a class which allows for a vector to be created holding any type or class. However I'd like to add additional functionality for numerical types. template <> class Vec<double> : ...

5

Solved

The following code: template <typename S, typename T> struct foo { void bar(); }; template <typename T> void foo <int, T>::bar() { } gives me the error invalid use of incomp...
Canonicals asked 2/10, 2008 at 23:47

1

I came across this issue while trying to specialize tuple_size/tuple_element for a custom class in C++17 for structured binding. Below code compiles in GCC, but not in clang (both trunk versions, ...

3

Solved

I was just reading the examples of C++20 Concepts. Now I am trying to create a function that will print out if the given type is a hash-table or not using concepts mixed with the partial-specializa...
Celt asked 19/3, 2019 at 5:14

1

Solved

I am not clear about the interaction of default template arguments in the context of partial specialization, for choosing which is the better matching template. This questions stems from code poste...

2

Solved

The following code: template<typename T, MyEnum K> __global__ void myKernel(const T a[]); template<typename T> __global__ void myKernel<T,SomeValueOfMyEnum>(const T a[]) { // im...
Somnambulate asked 13/11, 2013 at 16:49

1

Solved

I know that I can partially specialize class templates, and I know that I cannot partially specify function templates. What about variable templates? I can't find documentation on whether they can...

1

I have a template class/struct that looks like this: template <typename T, typename U> struct S { unsigned int operator()(T t, U u) const; }; And I would like to make sure that specializa...
Extinctive asked 9/8, 2018 at 9:19

2

Solved

I have a program that is as follows. There is a base template struct X and a partial specialisation with SFINAE. template <typename T, typename U = void> struct X{ X() { std::cout &l...
Needless asked 23/7, 2018 at 12:38

2

Solved

In Chapter 19.8.4 of the book "C++ Templates - The Complete Guide - Second Edition", the authors show how one can determine if a type is a class type in compile-time: #include <iostream> #in...
Valora asked 21/6, 2018 at 18:41

1

Solved

With reference to the following code #include <utility> #include <cassert> template <typename T> struct Wot; template <int... ints> struct Wot<std::index_sequence<i...
Auspicate asked 4/10, 2017 at 0:7

2

Solved

Are multiple class template specialisations valid, when each is distinct only between patterns involving template parameters in non-deduced contexts? A common example of std::void_t uses it to def...

© 2022 - 2025 — McMap. All rights reserved.