小编Duk*_*uke的帖子

Can two functors be compared for equality?

Is there a way for a method, which receives two functors as arguments, to find out if they are pointing to the same function? Specifically, having a struct like this:

struct FSMAction {
    void action1() const { std::cout << "Action1 called." << std::endl; }
    void action2() const { std::cout << "Action2 called." << std::endl; }
    void action3() const { std::cout << "Action3 called." << std::endl; }

private:
    // Maybe some object-specific stuff.
};
Run Code Online (Sandbox Code Playgroud)

And a method like this:

bool actionsEqual( …
Run Code Online (Sandbox Code Playgroud)

c++ functor c++11

6
推荐指数
1
解决办法
227
查看次数

Add transparency to PDF with libharu

I want to create a pdf with partially transparent polygons as the ellipse in the below image using libharu. The polygons come as RGBA, but libharu only has these fill methods:

HPDF_Page_SetCMYKFill()
HPDF_Page_SetGrayFill()
HPDF_Page_SetRGBFill() 
Run Code Online (Sandbox Code Playgroud)

There is no "A" channel for rgb. (There is a transparency mask for the whole image, but as I understand, this only makes a range of colors invisible in the whole image, which is not what I want.)

I am new to libharu, and not …

c++ libharu

5
推荐指数
1
解决办法
218
查看次数

是否可以比较两个指向成员函数的指针是否相等?

我之前已经问过类似的问题,但是现在我意识到这还不够具体。

我想做的是找出指向该类某个成员函数的两个指针,与该类的实际对象相结合,是否相等,因为它们都将“调用”(如下所述)同一个函数同一对象。基本上,在这段代码中:

bool isEqual(F* object1, void(F::*_fct1)(), 
             F* object2, void(F::*_fct2)())
{
    TSpecificFunctor<F> specFunc1(object1, fct1);
    TSpecificFunctor<F> specFunc2(object2, fct2);

    return /* Something */;
}
Run Code Online (Sandbox Code Playgroud)

是否存在/* Something */将返回trueiff specFunc1specFunc2指向同一给定对象的相同成员函数的东西?

在那里,TSpecificFunctor定义如下:

class TFunctor
{
public:
    virtual void call() = 0;
};

template <class TClass> class TSpecificFunctor : public TFunctor
{
public:
    TSpecificFunctor(TClass* _pt2Object, void(TClass::*_fpt)())
    {
        pt2Object = _pt2Object;
        fpt=_fpt; 
    }

    virtual void call() override
    { 
        (*pt2Object.*fpt)();
    }

private:
    void (TClass::*fpt)();
    TClass* pt2Object;
};
Run Code Online (Sandbox Code Playgroud)

换句话说,该函数应返回 …

c++ functor c++11

3
推荐指数
1
解决办法
96
查看次数

标签 统计

c++ ×3

c++11 ×2

functor ×2

libharu ×1