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;








1















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.










share|improve this question






























    1















    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.










    share|improve this question


























      1












      1








      1








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 12:03









      Jon Harper

      3,02621130




      3,02621130










      asked Mar 22 at 15:50









      VladVlad

      92




      92






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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();

          ;





          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            1














            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();

            ;





            share|improve this answer



























              1














              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();

              ;





              share|improve this answer

























                1












                1








                1







                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();

                ;





                share|improve this answer













                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();

                ;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 9:28









                Anthony WilliamsAnthony Williams

                52.8k9102140




                52.8k9102140





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript