Template specialization on array pointer with any layer of nesting Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Template specialization to use default type if class member typedef does not existPretty-print C++ STL containersReference level part 2Query about C++ template specialization and partial template specializationUsing const char** with Template SpecializationFunction template specialization - problems with pointersReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationspartial template specialization for template pointer to functionconstexpr array member with template specialization: inconsistent behavior cross compilersDelete templated struct partial specialization
Justification for leaving new position after a short time
What was Apollo 13's "Little Jolt" after MECO?
As an international instructor, should I openly talk about my accent?
Multiple options vs single option UI
Seek and ye shall find
Reattaching fallen shelf to wall?
Why did Israel vote against lifting the American embargo on Cuba?
Why did C use the -> operator instead of reusing the . operator?
Book with legacy programming code on a space ship that the main character hacks to escape
What *exactly* is electrical current, voltage, and resistance?
Is a 5 watt UHF/VHF handheld considered QRP?
What is a 'Key' in computer science?
Does Mathematica have an implementation of the Poisson Binomial Distribution?
Where did Arya get these scars?
What do you call the part of a novel that is not dialog?
How to translate "red flag" into Spanish?
My admission is revoked after accepting the admission offer
How would I use different systems of magic when they are capable of the same effects?
Additive group of local rings
Mistake in years of experience in resume?
What is /etc/mtab in Linux?
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
A strange hotel
Israeli soda type drink
Template specialization on array pointer with any layer of nesting
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Template specialization to use default type if class member typedef does not existPretty-print C++ STL containersReference level part 2Query about C++ template specialization and partial template specializationUsing const char** with Template SpecializationFunction template specialization - problems with pointersReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationspartial template specialization for template pointer to functionconstexpr array member with template specialization: inconsistent behavior cross compilersDelete templated struct partial specialization
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I need to write a template specialization which will work with pointers on arrays (these things: char(*)[]
). And we will write this code for that
// our class
template<typename T>
struct CoolStruct
static void Print(); // will print "Default"
;
//one specialization for sized arrays
template<typename T, size_t S>
struct CoolStruct<T(*)[S]>
static void Print(); // will print "T(*)[sized]"
;
// and one for arrays without size
template<typename T>
struct CoolStruct<T(*)[]>
static void Print(); // will print "T(*)[]"
;
And when in our code we will do something like this:
int (*arrptr)[10];
CoolClass<decltype(arrptr)>::Print();
The console will print "T(*)[sized]" as we expected (considering that we wrote implementation for all methods of course). But what if we will wrote our code like this:
int (**arrptr_d)[10];
CoolClass<decltype(arrptr_d)>::Print();
In this case the console will actually print "Default". We could write another specialization like this:
template<typename T, size_t S>
struct CoolStruct<T(**)[S]>
static void Print(); // will print "T(*)[sized]"
;
but I want to find another solution (I don't want to write another dozen specializations when I would need to use int(****)[]
). So considering we using C++17 standard, is there a way to do such a thing?
P.S. And yes, sorry for my terrible English; it is not my native language.
c++ templates c++17
add a comment |
I need to write a template specialization which will work with pointers on arrays (these things: char(*)[]
). And we will write this code for that
// our class
template<typename T>
struct CoolStruct
static void Print(); // will print "Default"
;
//one specialization for sized arrays
template<typename T, size_t S>
struct CoolStruct<T(*)[S]>
static void Print(); // will print "T(*)[sized]"
;
// and one for arrays without size
template<typename T>
struct CoolStruct<T(*)[]>
static void Print(); // will print "T(*)[]"
;
And when in our code we will do something like this:
int (*arrptr)[10];
CoolClass<decltype(arrptr)>::Print();
The console will print "T(*)[sized]" as we expected (considering that we wrote implementation for all methods of course). But what if we will wrote our code like this:
int (**arrptr_d)[10];
CoolClass<decltype(arrptr_d)>::Print();
In this case the console will actually print "Default". We could write another specialization like this:
template<typename T, size_t S>
struct CoolStruct<T(**)[S]>
static void Print(); // will print "T(*)[sized]"
;
but I want to find another solution (I don't want to write another dozen specializations when I would need to use int(****)[]
). So considering we using C++17 standard, is there a way to do such a thing?
P.S. And yes, sorry for my terrible English; it is not my native language.
c++ templates c++17
add a comment |
I need to write a template specialization which will work with pointers on arrays (these things: char(*)[]
). And we will write this code for that
// our class
template<typename T>
struct CoolStruct
static void Print(); // will print "Default"
;
//one specialization for sized arrays
template<typename T, size_t S>
struct CoolStruct<T(*)[S]>
static void Print(); // will print "T(*)[sized]"
;
// and one for arrays without size
template<typename T>
struct CoolStruct<T(*)[]>
static void Print(); // will print "T(*)[]"
;
And when in our code we will do something like this:
int (*arrptr)[10];
CoolClass<decltype(arrptr)>::Print();
The console will print "T(*)[sized]" as we expected (considering that we wrote implementation for all methods of course). But what if we will wrote our code like this:
int (**arrptr_d)[10];
CoolClass<decltype(arrptr_d)>::Print();
In this case the console will actually print "Default". We could write another specialization like this:
template<typename T, size_t S>
struct CoolStruct<T(**)[S]>
static void Print(); // will print "T(*)[sized]"
;
but I want to find another solution (I don't want to write another dozen specializations when I would need to use int(****)[]
). So considering we using C++17 standard, is there a way to do such a thing?
P.S. And yes, sorry for my terrible English; it is not my native language.
c++ templates c++17
I need to write a template specialization which will work with pointers on arrays (these things: char(*)[]
). And we will write this code for that
// our class
template<typename T>
struct CoolStruct
static void Print(); // will print "Default"
;
//one specialization for sized arrays
template<typename T, size_t S>
struct CoolStruct<T(*)[S]>
static void Print(); // will print "T(*)[sized]"
;
// and one for arrays without size
template<typename T>
struct CoolStruct<T(*)[]>
static void Print(); // will print "T(*)[]"
;
And when in our code we will do something like this:
int (*arrptr)[10];
CoolClass<decltype(arrptr)>::Print();
The console will print "T(*)[sized]" as we expected (considering that we wrote implementation for all methods of course). But what if we will wrote our code like this:
int (**arrptr_d)[10];
CoolClass<decltype(arrptr_d)>::Print();
In this case the console will actually print "Default". We could write another specialization like this:
template<typename T, size_t S>
struct CoolStruct<T(**)[S]>
static void Print(); // will print "T(*)[sized]"
;
but I want to find another solution (I don't want to write another dozen specializations when I would need to use int(****)[]
). So considering we using C++17 standard, is there a way to do such a thing?
P.S. And yes, sorry for my terrible English; it is not my native language.
c++ templates c++17
c++ templates c++17
edited Mar 26 at 12:03
Jon Harper
3,02621130
3,02621130
asked Mar 22 at 15:50
VladVlad
92
92
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you don't care about other pointers, you could do a partial specialization that delegates double pointers to the specialization for single pointers:
template<typename Pointee>
struct CoolStruct<Pointee**>
static void Print()
CoolStruct<Pointee*>::Print();
;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303378%2ftemplate-specialization-on-array-pointer-with-any-layer-of-nesting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you don't care about other pointers, you could do a partial specialization that delegates double pointers to the specialization for single pointers:
template<typename Pointee>
struct CoolStruct<Pointee**>
static void Print()
CoolStruct<Pointee*>::Print();
;
add a comment |
If you don't care about other pointers, you could do a partial specialization that delegates double pointers to the specialization for single pointers:
template<typename Pointee>
struct CoolStruct<Pointee**>
static void Print()
CoolStruct<Pointee*>::Print();
;
add a comment |
If you don't care about other pointers, you could do a partial specialization that delegates double pointers to the specialization for single pointers:
template<typename Pointee>
struct CoolStruct<Pointee**>
static void Print()
CoolStruct<Pointee*>::Print();
;
If you don't care about other pointers, you could do a partial specialization that delegates double pointers to the specialization for single pointers:
template<typename Pointee>
struct CoolStruct<Pointee**>
static void Print()
CoolStruct<Pointee*>::Print();
;
answered Mar 26 at 9:28
Anthony WilliamsAnthony Williams
52.8k9102140
52.8k9102140
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303378%2ftemplate-specialization-on-array-pointer-with-any-layer-of-nesting%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown