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 7815949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:41:23+00:00 2026-06-02T05:41:23+00:00

What I mean by an ‘intermediate’ functor is: a normal functor where one of

  • 0

What I mean by an ‘intermediate’ functor is: a normal functor where one of the arguments can be specified at call-time. The problem is that I have an animation timeline (essentially scalar values at particular frames), and the output of this needs to be piped to and from getter/setter methods within the objects to be animated. Here is a simplified example of what I was attempting:

template < class ObjType, class Getter, class Setter, typename Scalar >
class Sy_propertyBridge : public Sy_abstractPropertyBridge
{
public:
                        Sy_propertyBridge( ObjType* object, Getter getter,
                                           Setter setter )
                            : obj_( object ), get_( getter ),
                              set_( setter ) {}
    virtual            ~Sy_propertyBridge() {}

    inline virtual float get() const
                        {
                            //  Cannot handle default arguments.
                            Scalar tmp = ( obj_->*get_ )();
                            return static_cast< float >( tmp );
                        }
    inline virtual void set( float value )
                        {
                            Scalar tmp = static_cast< Scalar >( value );
                            ( obj_->*set_ )( tmp );
                        }
private:
    ObjType*            obj_;
    Getter              get_;
    Setter              set_;
};

The timeline only holds floats, so whatever scalar type the object uses for it’s getter/setter methods, must be cast (I have a partial specialisation for floats that does away with the cast). ObjType is the animated object type, Getter and Setter are pointers-to-methods, and Scalar is the type Getter and Setter and expected to deal with.

I thought this would be fine, but compilation failed because some of the getter/setters had other default-initialised arguments. I didn’t think this would be a problem, because they’re default! But when the compiler expected more args for the pointer-to-method than I was supplying, it failed.

I then tried using variadic template args so the default values could be manually put in, but fell at the first hurdle because I can’t store the parameter pack as a member to be repeatedly applied as args to the pointer-to-methods. I have also been looking at std::function and std::bind, I was hoping to be able to store a std::function as a member with the getter/setter method’s default args preset – and change the appropriate arg for one from the timeline just before calling. Only I can’t find a way to do that…

Does anyone have any suggestions to achieve what I am aiming for? Or is my design fundamentally flawed and there is an easier approach?

  • 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-02T05:41:25+00:00Added an answer on June 2, 2026 at 5:41 am

    std::function would be the way to go. Will just use std::function<Scalar(const ObjType*)> as your getter, std::function<void(ObjType*, Scalar)> as your setter (if the Scalars are implicitly convertible to/from floats, I’d even use std::function<float(ObjType const*)> and std::function<void(ObjType*, float)>, resp.). You can initialize these eg. with lambda functions:

    Sy_propertyBridge(my_obj, 
      [](const MyObjType* o) -> float { return o->opacity; }, 
      [](const MyObjType* o, float f) { o->opacity=f; })
    

    Note that there may be more elegant ways of doing this (eg. there could be only one function that could serve both as a getter and a setter).

    Taking it even further, you could

    • get rid of the obj_ member variable
    • get rid of the o parameters to the functions

    The lambdas would then have to remember the object they will operate on. So the above constructor call would become

    Sy_propertyBridge(
      []() -> float { return my_obj->opacity; }, 
      [](float f) { my_obj->opacity=f; })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I mean settings that can be changed from task manager like realtime or idle.
I mean a tool that can extract certain contents from old .NET 1.1 WinForm
I mean you can login both https://mail.google.com/ and https://mail.google.com/a/company.com at the same time. The
I mean that I have developed a new but simple RISC CPU based on
I mean, I use to have this widget : <script src=http://www.mywebsite.com/widget/widget.js?type=normal type=text/javascript></script> <div id=archie-container></div>
I mean things like: FK1 -> 1FK2 -> 2PK Please, note that 1FK2 is
I mean, if I have an object and I apply 3 transforms to it,
I mean, an add-in that allows me to associate image and sound files with
I mean we have a class which is already loaded in JVM. and in
I mean, how can I find which of two elements belongs to a node

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.