Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:31:04+00:00 2026-06-10T06:31:04+00:00

I already asked a similar question here , however I didn’t really get the

  • 0

I already asked a similar question here, however I didn’t really get the answer I wanted because my question was poorly formulated and the examples were bad. So I give it another shot, with hopefully a better explanation and better code .

The code bellow has been stripped out of unnecessary details but it works .
The thing is I would like to use Template Argument Deduction, if possible, to simplify the templated function call .

I have a factory which creates commands. To create a command, I use a call like that one :

mCommandFactory.createCommand<
                        DoSomeStuff, 
                        ParameterType1, 
                        ParameterType2, 
                        ParameterType3, 
                        ParameterType4
                        >
                        (std:string("some description"), 
                         parameter1, 
                         parameter2, 
                         parameter3, 
                         parameter4);

As you probably have guessed, parameter1 type is ParameterType1, and so on … .

Now if we look at the definition of the command – DoSomeStuff- itself :

class DoSomeStuff : public UndoableCommand< ParameterType1 , ParameterType2, ParameterType3 , ParameterType4 >
    {
    public:
      DoSomeStuff(... /* arguments which are needed for precessing the command and undoing it*/ );
      ~DoSomeStuff() throw();
      void executeImpl();
      void undoImpl();

    protected:
              ... /* members which are needed for precessing the command and undoing it*/ 
    };

As you can see, ParameterTypeN information is already inside DoSomeStuff declaration.

I was wondering if it was possible somehow to replace the createCommand call above by something simpler :

mCommandFactory.createCommand<DoSomeStuff>
                        (std:string("some description"), 
                         parameter1, 
                         parameter2, 
                         parameter3, 
                         parameter4);

Here is the CommandFactory code :

    class CommandFactory
    {
    private:
          // some stuff used to initialize objects created by this factory 

    public:
        CommandFactory(...) : ... /* members initialization */

        {  
        }


        template <class CommandType, typename P1, typename P2, typename P3, typename P4> 
        void createCommand(juce::String& description,P1 p1, P2 p2, P3 p3, P4 p4)
        {
            Undoable* cmdPtr = new CommandType(p1, p2, p3, p4);
            ...
            // init cmdPtr

            (*cmdPtr)();            
        }

Basically the point would be to move the complexity inside CommandFactory, to keep the “client code” (the call to createCommand) as simple and short as possible.

Any ideas ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:31:05+00:00Added an answer on June 10, 2026 at 6:31 am

    Not sure I understand the question correctly, but this should work.

    template<typename ParameterType1 , typename ParameterType2, typename ParameterType3 , typename ParameterType4>
    class UndoableCommand
    {
    public:
        UndoableCommand(ParameterType1 p1, ParameterType2 p2, ParameterType3 p3, ParameterType4 p4)
        {}
    };
    
    class DoSomeStuff : public UndoableCommand< int ,double, std::string , int>
    {
    public:
        DoSomeStuff(int p1, double p2, std::string p3, int p4)
            :UndoableCommand(p1,p2,p3,p4)
        {}
    };
    
    class CommandFactory
    {
    public:
        CommandFactory()
        {}
    
        template <class CommandType, typename P1, typename P2, typename P3, typename P4> 
        void createCommand( std::string& description,P1 p1, P2 p2, P3 p3, P4 p4)
        {
            UndoableCommand<P1,P2,P3,P4> * cmdPtr = new CommandType(p1, p2, p3, p4);
    
        }
     };
    

    Used as such

    CommandFactory fact;
    fact.createCommand<DoSomeStuff>(std::string("description"),1,2.0,std::string("3"),4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already asked the same question over at dev.twitter.com , however, I didn't get
I already asked similar question here, but I still get some errors, so I
I already asked a similar question, PE Header requirements , but I'm not really
This is similar to a question that has already been asked. However, I am
I have asked a similar question before, but didn't get very good results. I've
I already asked a similar question but still can't get it to work. I
I'm afraid very similar question has been asked already here , but for some
I have already asked a similar question here: Python open raw audio data file
I have already asked a similar question on this, however after seeing the railscast
A similiar question was asked already here How to get nested RDF/XML from Jena?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.