Wrapping Inherited Templates in Cython? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Interfacing C++11 array with CythonPrefer composition over inheritance?Why can templates only be implemented in the header file?Difference between private, public, and protected inheritancePython class inherits objectWhat are the nuances of scope prototypal / prototypical inheritance in AngularJS?How do I pass one C++ class (reference) to another when using Cython?Cython - copy constructorsWhy not inherit from List<T>?Wrapping a c++ singleton with cythonCalling Cython from c++ with not built-in types

Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?

Effects on objects due to a brief relocation of massive amounts of mass

What is the meaning of 'breadth' in breadth first search?

What was the first language to use conditional keywords?

What is this clumpy 20-30cm high yellow-flowered plant?

Find 108 by using 3,4,6

Crossing US/Canada Border for less than 24 hours

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Disembodied hand growing fangs

Do I really need to have a message in a novel to appeal to readers?

How to react to hostile behavior from a senior developer?

Sum letters are not two different

Significance of Cersei's obsession with elephants?

Can the Great Weapon Master feat's damage bonus and accuracy penalty apply to attacks from the Spiritual Weapon spell?

Why do we need to use the builder design pattern when we can do the same thing with setters?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

An adverb for when you're not exaggerating

Is there any word for a place full of confusion?

How can I reduce the gap between left and right of cdot with a macro?

Is it fair for a professor to grade us on the possession of past papers?

Can a new player join a group only when a new campaign starts?

What would you call this weird metallic apparatus that allows you to lift people?

What is the difference between globalisation and imperialism?

What's the meaning of "fortified infraction restraint"?



Wrapping Inherited Templates in Cython?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Interfacing C++11 array with CythonPrefer composition over inheritance?Why can templates only be implemented in the header file?Difference between private, public, and protected inheritancePython class inherits objectWhat are the nuances of scope prototypal / prototypical inheritance in AngularJS?How do I pass one C++ class (reference) to another when using Cython?Cython - copy constructorsWhy not inherit from List<T>?Wrapping a c++ singleton with cythonCalling Cython from c++ with not built-in types



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to write a cython wrapper for some templated C++ code. I'm pretty familiar with wrapping something written like Bar. i.e. (with details removed)



 ctypedef enum enum_t "enum_t":
OPT1 "OPT1",
OPT2 "OPT2",
OPT3 "OPT3"

cdef cppclass Bar[A, B, T, ALLOCATOR=*]

new Bar[OPT1, OPT2, float]


But I'm having trouble understanding what the practice is for wrapping instances of something like Bar<OPT1, OPT2, T> or Bar<OPT3, OPT4, T> defined below. Could someone point me in the right direction? What I've tried has given me an "OPT1 is ambiguous" error at compilation.



typedef enum

OPT1,
OPT2,
OPT3,
enum_t;

template<class T, class Allocator = std::allocator<T> >
class BarBase : public Foo<T, Allocator>, public mpi::MPIObject

//Generic class methods and variables


template<enum_t A, enum_t B, class T, class Allocator = std::allocator<T> >
class Bar : public BarBase<T, Allocator>

public:
private:
;

template<typename T>
class Bar<OPT1, OPT2, T> : public BarBase<T>

//Specific class methods here


template<typename T>
class Bar<OPT3, OPT4, T> : public BarBase<T>

//Specific class methods here










share|improve this question






























    0















    I'm trying to write a cython wrapper for some templated C++ code. I'm pretty familiar with wrapping something written like Bar. i.e. (with details removed)



     ctypedef enum enum_t "enum_t":
    OPT1 "OPT1",
    OPT2 "OPT2",
    OPT3 "OPT3"

    cdef cppclass Bar[A, B, T, ALLOCATOR=*]

    new Bar[OPT1, OPT2, float]


    But I'm having trouble understanding what the practice is for wrapping instances of something like Bar<OPT1, OPT2, T> or Bar<OPT3, OPT4, T> defined below. Could someone point me in the right direction? What I've tried has given me an "OPT1 is ambiguous" error at compilation.



    typedef enum

    OPT1,
    OPT2,
    OPT3,
    enum_t;

    template<class T, class Allocator = std::allocator<T> >
    class BarBase : public Foo<T, Allocator>, public mpi::MPIObject

    //Generic class methods and variables


    template<enum_t A, enum_t B, class T, class Allocator = std::allocator<T> >
    class Bar : public BarBase<T, Allocator>

    public:
    private:
    ;

    template<typename T>
    class Bar<OPT1, OPT2, T> : public BarBase<T>

    //Specific class methods here


    template<typename T>
    class Bar<OPT3, OPT4, T> : public BarBase<T>

    //Specific class methods here










    share|improve this question


























      0












      0








      0








      I'm trying to write a cython wrapper for some templated C++ code. I'm pretty familiar with wrapping something written like Bar. i.e. (with details removed)



       ctypedef enum enum_t "enum_t":
      OPT1 "OPT1",
      OPT2 "OPT2",
      OPT3 "OPT3"

      cdef cppclass Bar[A, B, T, ALLOCATOR=*]

      new Bar[OPT1, OPT2, float]


      But I'm having trouble understanding what the practice is for wrapping instances of something like Bar<OPT1, OPT2, T> or Bar<OPT3, OPT4, T> defined below. Could someone point me in the right direction? What I've tried has given me an "OPT1 is ambiguous" error at compilation.



      typedef enum

      OPT1,
      OPT2,
      OPT3,
      enum_t;

      template<class T, class Allocator = std::allocator<T> >
      class BarBase : public Foo<T, Allocator>, public mpi::MPIObject

      //Generic class methods and variables


      template<enum_t A, enum_t B, class T, class Allocator = std::allocator<T> >
      class Bar : public BarBase<T, Allocator>

      public:
      private:
      ;

      template<typename T>
      class Bar<OPT1, OPT2, T> : public BarBase<T>

      //Specific class methods here


      template<typename T>
      class Bar<OPT3, OPT4, T> : public BarBase<T>

      //Specific class methods here










      share|improve this question
















      I'm trying to write a cython wrapper for some templated C++ code. I'm pretty familiar with wrapping something written like Bar. i.e. (with details removed)



       ctypedef enum enum_t "enum_t":
      OPT1 "OPT1",
      OPT2 "OPT2",
      OPT3 "OPT3"

      cdef cppclass Bar[A, B, T, ALLOCATOR=*]

      new Bar[OPT1, OPT2, float]


      But I'm having trouble understanding what the practice is for wrapping instances of something like Bar<OPT1, OPT2, T> or Bar<OPT3, OPT4, T> defined below. Could someone point me in the right direction? What I've tried has given me an "OPT1 is ambiguous" error at compilation.



      typedef enum

      OPT1,
      OPT2,
      OPT3,
      enum_t;

      template<class T, class Allocator = std::allocator<T> >
      class BarBase : public Foo<T, Allocator>, public mpi::MPIObject

      //Generic class methods and variables


      template<enum_t A, enum_t B, class T, class Allocator = std::allocator<T> >
      class Bar : public BarBase<T, Allocator>

      public:
      private:
      ;

      template<typename T>
      class Bar<OPT1, OPT2, T> : public BarBase<T>

      //Specific class methods here


      template<typename T>
      class Bar<OPT3, OPT4, T> : public BarBase<T>

      //Specific class methods here







      c++ inheritance cython wrapper templating






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 21:15







      AlethicSupporter

















      asked Mar 8 at 20:43









      AlethicSupporterAlethicSupporter

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Cython doesn't really support non-type template parameters. In previous questions when using int template parameters I've recommended using "fake" classes with names signed on generate the correct C++ code. The same principle applies here:



          cdef extern from "X.hpp": 
          cdef cppclass OPT1:
          pass
          cdef cppclass OPT2:
          pass

          cdef cppclass Bar[A, B, T]:
          pass

          def f():
          cdef Bar[OPT1,OPT2,float]* p = new Bar[OPT1,OPT2,float]()


          I've simply told Cython that OPT1 and OPT2 are classes rather than enum values and this tricks Cython into generating the correct code.






          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%2f55070718%2fwrapping-inherited-templates-in-cython%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









            0














            Cython doesn't really support non-type template parameters. In previous questions when using int template parameters I've recommended using "fake" classes with names signed on generate the correct C++ code. The same principle applies here:



            cdef extern from "X.hpp": 
            cdef cppclass OPT1:
            pass
            cdef cppclass OPT2:
            pass

            cdef cppclass Bar[A, B, T]:
            pass

            def f():
            cdef Bar[OPT1,OPT2,float]* p = new Bar[OPT1,OPT2,float]()


            I've simply told Cython that OPT1 and OPT2 are classes rather than enum values and this tricks Cython into generating the correct code.






            share|improve this answer



























              0














              Cython doesn't really support non-type template parameters. In previous questions when using int template parameters I've recommended using "fake" classes with names signed on generate the correct C++ code. The same principle applies here:



              cdef extern from "X.hpp": 
              cdef cppclass OPT1:
              pass
              cdef cppclass OPT2:
              pass

              cdef cppclass Bar[A, B, T]:
              pass

              def f():
              cdef Bar[OPT1,OPT2,float]* p = new Bar[OPT1,OPT2,float]()


              I've simply told Cython that OPT1 and OPT2 are classes rather than enum values and this tricks Cython into generating the correct code.






              share|improve this answer

























                0












                0








                0







                Cython doesn't really support non-type template parameters. In previous questions when using int template parameters I've recommended using "fake" classes with names signed on generate the correct C++ code. The same principle applies here:



                cdef extern from "X.hpp": 
                cdef cppclass OPT1:
                pass
                cdef cppclass OPT2:
                pass

                cdef cppclass Bar[A, B, T]:
                pass

                def f():
                cdef Bar[OPT1,OPT2,float]* p = new Bar[OPT1,OPT2,float]()


                I've simply told Cython that OPT1 and OPT2 are classes rather than enum values and this tricks Cython into generating the correct code.






                share|improve this answer













                Cython doesn't really support non-type template parameters. In previous questions when using int template parameters I've recommended using "fake" classes with names signed on generate the correct C++ code. The same principle applies here:



                cdef extern from "X.hpp": 
                cdef cppclass OPT1:
                pass
                cdef cppclass OPT2:
                pass

                cdef cppclass Bar[A, B, T]:
                pass

                def f():
                cdef Bar[OPT1,OPT2,float]* p = new Bar[OPT1,OPT2,float]()


                I've simply told Cython that OPT1 and OPT2 are classes rather than enum values and this tricks Cython into generating the correct code.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 10 at 15:09









                DavidWDavidW

                15.2k12443




                15.2k12443





























                    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%2f55070718%2fwrapping-inherited-templates-in-cython%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

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко