template-specialization

Allocator specialized for array types in c++14?

谁都会走 提交于 2021-02-08 01:26:41
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

那年仲夏 提交于 2021-02-08 01:24:22
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

落爺英雄遲暮 提交于 2021-02-08 01:23:08
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

孤人 提交于 2021-02-08 01:22:35
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

One template specialization for several enum values

为君一笑 提交于 2021-02-07 13:17:26
问题 Normally if I want to have a templated (data) class by enum I would write something like this enum class Modes : int { m1 = 1, m2 = 2, m3 = 3 }; template <Modes M> class DataHolder { }; template<> class DataHolder<Modes::m1> { public: int a = 4; }; Then if I want the same specialization for the Modes::m1 as for the Modes::m2 I would write the same specialization again. Is there a way to write one specialization for several enum values? I have tried it with SFINAE, but I am not succesfull.

using template specialization

一曲冷凌霜 提交于 2021-02-07 12:58:25
问题 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 typedefs: template<typename T> using YetAnotherVector = std::vector<T> Is there a way to define a template specialization for these using constructs similar to specializations for struct templates? I tried the following: template<> using YetAnotherVector<int> = AFancyIntVector; but it yielded a compile error. Is this

c++ friend operator template specialization

亡梦爱人 提交于 2021-02-07 09:37:34
问题 I have a generalized modulo struct called quotient_ring . The relevant bits are shown below. template <typename R = long long> struct quotient_ring{ using Q = quotient_ring; R x, m; ... template <typename T> friend constexpr std::basic_ostream<T> &operator<< (std::basic_ostream<T> &str, const Q &q){ return str << '(' << q.x << ")%(" << q.m << ')'; } }; This operator << would print something like 2 mod 7 as (2)%(7) . The reason I need the brackets is because the type R can become very nested.

Ambiguous template with SFINAE dummy parameter

夙愿已清 提交于 2021-02-07 02:54:49
问题 Consider a case where one needs to verify a type T with another template g (could be some enable_if expression, for example) inside a dummy parameter of another template, like this: template<class> struct g { typedef void type; }; template<class, class> struct f {}; template<class T> struct f<T, void> {}; // Case A template<class T> struct f<T*, typename g<T>::type> {}; // Case B int main() { f<int*, void> test; } Here, for the sake of simplicity g doesn't really do anything. The second

Ambiguous template with SFINAE dummy parameter

梦想与她 提交于 2021-02-07 02:54:49
问题 Consider a case where one needs to verify a type T with another template g (could be some enable_if expression, for example) inside a dummy parameter of another template, like this: template<class> struct g { typedef void type; }; template<class, class> struct f {}; template<class T> struct f<T, void> {}; // Case A template<class T> struct f<T*, typename g<T>::type> {}; // Case B int main() { f<int*, void> test; } Here, for the sake of simplicity g doesn't really do anything. The second

std::remove_reference explained?

无人久伴 提交于 2021-02-04 09:10:08
问题 I saw possible implementations for std::remove_reference as below template< class T > struct remove_reference {typedef T type;}; template< class T > struct remove_reference<T&> {typedef T type;}; template< class T > struct remove_reference<T&&> {typedef T type;}; Why is it that there are specializations for lvalue and rvalue reference ? Won't the general template itself be sufficient and remove the reference? I'm confused here because in the T& or T&& specialization if I try to use ::type I