template-specialization Questions

5

Solved

I've been on this problem all morning with no result whatsoever. Basically, I need a simple metaprogramming thing that allows me to branch to different specializations if the parameter passed is a ...
Astatic asked 2/5, 2013 at 12:3

3

I have some hand-vectorized C++ code that I'm trying to make a distribute-able binary for via function multiversioning. Since the code uses SIMD intrinsics for different instruction sets (SSE2, AVX...
Hypercorrection asked 25/10, 2020 at 19:7

4

Solved

A textbook I have notes that you can provide your own implementation for standard library functions like swap(x,y) via template specialization or function overloading. This would be useful for any ...
Sustenance asked 18/8, 2011 at 13:17

3

I have this class template template <typename T> class Wrapper { public: virtual void parse(std::string s) = 0; protected: T value; }; ideally, each type should know how to parse itse...

4

Solved

Given: struct A { virtual bool what() = 0; }; template<typename T, typename Q> struct B : public A { virtual bool what(); }; I want to partially specialize what like: template<typen...
Greenleaf asked 23/4, 2012 at 16:31

1

Solved

Consider the following code: #include<concepts> template<typename> void foo() { } template<std::integral> void foo() { } template<> void foo<bool>() { } int main...

4

Solved

I would like to have a special formatter for BASECLASS and all derived classes. I have the following classes: struct BASECLASS { ... }; struct SPECIALFORMAT : BASECLASS { ... } struct ANOTHERSPECI...
Proudlove asked 29/1, 2014 at 17:4

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&...

2

Solved

I am currently learning C++ in-depth, and I have come across something that has stumped for a couple hours now. Why is it when I make a template and then specialize it, that I can't call or define ...
Courtnay asked 28/10, 2011 at 4:41

1

Solved

I have a user-defined numeric type S for which I specialized std::numeric_limits<T>. Although I specialized for S only, my custom max() is also used for cv-qualified S, at least with recent v...
Referent asked 8/6, 2023 at 18:49

1

Solved

From clang 9.0.0 onwards, all versions of clang reject the following code when compiled with -std=c++17 (or -std=c++20): #include <utility> template<class L, std::size_t N> struct A; ...
Launcher asked 26/5, 2023 at 19:54

1

Solved

In Is it safe to define a specialization for std::array the questioner asks if it's safe to specialize std::array for a program defined type which has an expensive default constructor. The goal is ...
Merozoite asked 21/12, 2022 at 18:34

1

Solved

I have a class with several template methods, i.e.: class MessageEndpoint { public: using SupportedMessages = boost::mp11::mp_list<messaging::MessageType1, messaging::MessageType2, messag...

3

Consider the following program: template<template<typename ...> class> struct foo {}; template<template<typename> class C> struct foo<C> {}; int main() {} Clang r...
Saturant asked 20/2, 2018 at 20:46

6

Solved

Pretty sure I know the answer to this already, but it's worth a shot. So, say I have a typelist: template <typename ...Ts> struct typelist{}; That contains some objects: struct foo{}; st...
Soilasoilage asked 7/9, 2015 at 18:23

4

I'm reading Primer C++ > Adventures in Functions > Templates > Explicit Specialization. To show the reason/use for Explicit Specialization, a case is illustrated: Consider a swap templat...

3

Solved

Is it possible to do the following specialization in C#? I can do this in C++ but do not understand how to achieve the same result in C#. class GenericPrinter<T> { public void Print() { C...
Picture asked 7/11, 2016 at 17:7

2

Solved

Context: To our surprise, MSVC with C++20 mode and two-phase compliance enabled accepts the following code: template<class T> class X { friend int foo<X>(X x); int a = 10; }; templa...

3

Solved

Usual template structs can be specialized, e.g., template<typename T> struct X{}; template<> struct X<int>{}; C++11 gave us the new cool using syntax for expressing template t...
Axe asked 10/11, 2014 at 13:0

2

According to https://eel.is/c++draft/temp.expl.spec#7: If a template, a member template or a member of a class template is explicitly specialized, a declaration of that specialization shall be rea...
Sudorific asked 3/3, 2022 at 10:37

2

Solved

I'd appreciate help figuring out what going on in this problem that's come up in my code which I've reduced to the following: typedef unsigned short ushort; template<typename T = ushort*> s...
Neutralization asked 22/2, 2017 at 12:38

5

I would like to define a C++ template specialization that applies to all subclasses of a given base class. Is this possible? In particular, I'd like to do this for STL's hash<>. hash<> is d...
Phemia asked 1/10, 2011 at 17:39

2

Is there a way to establish at compile time if a certain function template was specialized? For example, assume the following function template: template<size_t N> void foo(); I want to test...

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"; } ...

© 2022 - 2025 — McMap. All rights reserved.