1

I use the Boost.Parameter library for providing named parameters to a constructor.

BOOST_PARAMETER_NAME(windowFunction)

namespace detail
{

struct ClassAImpl
{
    template <class ArgumentPack>
    ClassAImpl(ArgumentPack const& args)
        : mWindowFun(args[_windowFunction])
            , [...]
    {

    }

    boost::function<bool(int, int)> mWindowFun;
    [...]
};
}

struct ClassA : detail::ClassAImpl
{
    BOOST_PARAMETER_CONSTRUCTOR(
            ClassA, (detail::ClassAImpl), tag
          , (optional (windowFunction,*)
            [...]))
};

Usually windowFunction will be copied by the boost::function object, however I want to also be able to pass by reference with boost::ref.

However when I pass a function object with boost::ref the reference_wrapper<T> is removed and the ArgumentPack contains a reference to the T value.

Question: Is there a way to prevent the removal of the reference_wrapper<T> wrapper?

Example:

SomeFunctionObject s;
ClassA a(windowFunction = boost::ref(s));

will have SomeFunctionObject& s passed to mWindowFun in the constructor of ClassAImpl instead of const reference_wrapper<SomeFunctionObject>&. Thus, s will be copied by boost::function which is undesirable.

1 Answer 1

1

This seems currently not possible as Boost Parameter is explicitly unwrapping reference_wrappers.

This is necessary for allowing to pass positional arguments by reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.