partial-specialization

C++ Partial template specialization - design simplification

好久不见. 提交于 2019-12-11 03:09:30
问题 I am working on a pipeline/dataflow design pattern. I have a class 'algorithm data output' ( AlgorithmOutput ) that acts as an interface between two connected network segments. In particular, it provides method templates getOutput<size_t N> that are used for the data output from an object of the type 'data transmitter'. The current design is based on the idea that users derive from the class AlgorithmOutput and provide a finite number of implementations of the method template getOutput<size_t

Specializing a class template constructor

半世苍凉 提交于 2019-12-10 23:27:23
问题 I'm messing around with template specialization and I ran into a problem with trying to specialize the constructor based on what policy is used. Here is the code I am trying to get to work. #include <cstdlib> #include <ctime> class DiePolicies { public: class RollOnConstruction { }; class CallMethod { }; }; #include <boost/static_assert.hpp> #include <boost/type_traits/is_same.hpp> template<unsigned sides = 6, typename RollPolicy = DiePolicies::RollOnConstruction> class Die { // policy type

CPP templated member function specialization

本小妞迷上赌 提交于 2019-12-10 19:42:22
问题 I'm trying to specialize the member function moment() only (not the hole class) like this: template<class Derived, class T> class AbstractWavelet { public: [...] template<bool useCache> const typename T::scalar moment(const int i, const int j) const { return abstractWaveletSpecialization<Derived, T, useCache>::moment(static_cast<const Derived*>(this), i, j); } template<bool useCache> friend const typename T::scalar abstractWaveletSpecialization<Derived, T, useCache>::moment(const Derived*

Why does the C++ standard not allow function template partial specialization?

一笑奈何 提交于 2019-12-10 17:21:06
问题 And before you downvote, yes I could have read the whole book from Stroustrup where it's maybe written somewhere in a side not. But maybe someone else asked themselves the same question and found a good answer. At least to me it seems like this would be handy to have. 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 it clear that it is a partial specialization.

Why is in-class partial specialization well-formed?

≯℡__Kan透↙ 提交于 2019-12-10 15:37:19
问题 According to [temp.class.spec] 5/ (emphasis mine) A class template partial specialization may be declared or redeclared in any namespace scope in which the corresponding primary template may be defined This would suggest that partial specialization (just like in case of explicit specialization) have to appear in the namespace scope. This is actually confirmed by the example below the paragraph: template<class T> struct A { struct C { template<class T2> struct B { }; }; }; // partial

C++ Templates: Partial Template Specifications and Friend Classes

不想你离开。 提交于 2019-12-10 03:00:42
问题 is it possible to somehow make a partial template specification a friend class? I.e. consider you have the following template class template <class T> class X{ T t; }; Now you have partial specializations, for example, for pointers template <class T> class X<T*>{ T* t; }; What I want to accomplish is that every possible X<T*> is a friend class of X<S> for ANY S . I.e. X<A*> should be a friend of X<B> . Of course, I thought about a usual template friend declaration in X: template <class T>

Build error with template template parameter only after both members are parametrized

不羁岁月 提交于 2019-12-09 13:58:05
问题 I am trying to pass a template template parameter whom its parameter is a non-type value of type equal to a subtype of a previous template parameter (whew! that was as hard to say as it is to read!), and i'm having some build errors after trying to join the results in a single parametrized templates. I have the following code (which compiles just fine with g++ 4.4.1 and -std=c++0x): #include <iostream> using namespace std; enum class Labels { A , B }; template <Labels L> struct LabelTypeMap {

Get the signed/unsigned variant of an integer template parameter without explicit traits

怎甘沉沦 提交于 2019-12-09 05:08:45
问题 I am looking to define a template class whose template parameter will always be an integer type. The class will contain two members, one of type T , and the other as the unsigned variant of type T -- i.e. if T == int , then T_Unsigned == unsigned int . My first instinct was to do this: template <typename T> class Range { typedef unsigned T T_Unsigned; // does not compile public: Range(T min, T_Unsigned range); private: T m_min; T_Unsigned m_range; }; But it doesn't work. I then thought about

Static template member function for template class

孤街浪徒 提交于 2019-12-08 05:44:26
问题 I have a template class and a template member function: template<class T1> struct A{ template<class T2> static int f(){return 0;} }; I want to specialize for a case when T1 and T2 are the same, For example, define the case A<T>::f<T> for any T . but I can't find the combination of keywords to achieve this. How can I partially (?) specialize a combination of template class and a template static function? These are my unsuccessful attempts, and the error messages: 1) Specialize inside the class

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

三世轮回 提交于 2019-12-08 05:40:02
问题 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 following: #include <tr1/type_traits> #include <iostream> template<bool, typename _Tp = void> struct enable_if { }; template<typename _Tp> struct enable_if<true, _Tp> { typedef _Tp type; }; template< typename T > inline void foo_impl( typename enable_if<