# SoftBank Robotics documentation What's new in NAOqi 2.8?

# qi::AnyFunction

This class is a type-erased pointer to a function. It has value semantics.

## Summary

Global Classes

- class qi::AnyFunction

  Functions (class qi::AnyFunction)

  qi::AnyFunction::operator bool

  qi::AnyFunction::operator=

  qi::AnyFunction::~AnyFunction

  qi::AnyFunction::call

  qi::AnyFunction::from

  qi::AnyFunction::resultType

  qi::AnyFunction::argumentsType

  qi::AnyFunction::replaceFirstArgument

  qi::AnyFunction::parametersSignature

  qi::AnyFunction::swap

  qi::AnyFunction::dropFirstArgument

  qi::AnyFunction::AnyFunction

  qi::AnyFunction::operator()

  qi::AnyFunction::prependArgument

  qi::AnyFunction::returnSignature

  qi::AnyFunction::fromDynamicFunction

  qi::AnyFunction::functionType

## Detailed Description

It is possible to create a `qi::AnyFunction` from any functor (including `boost::function`). By using fromDynamicFunction, you can provide a “variadic” function that will receive a vector of references to its arguments.

    qi::AnyFunction freeFunc = qi::AnyFunction::from(someFunc);
    qi::AnyFunction memberFunc = qi::AnyFunction::from(Class::func, myObj);
    // if you use boost::bind or qi::bind, you must explicitly cast to the right
    // signature
    qi::AnyFunction memberFunc = qi::AnyFunction::from(
        boost::function<int(int value1, const std::string& value2)>(
          boost::bind(someFunc, _1, "argument")));

You can then call the function with a vector of arguments or by giving the arguments as in a normal function call.

Warning

The caller is responsible for destroying its `qi::AnyReference` to the returned value when using type-erased calls. You can store the returned reference in a `qi::AnyValue` to benefit from RAII destruction.

    // typed call
    int value = func.call<int>(42);

    // using operator()
    qi::AnyValue ret(func(42), false, true);
    std::cout << ret.toInt() << std::endl;

    // type-erased call
    qi::AnyReferenceVector args;
    args.push_back(qi::AnyReference::from(42));
    ret.reset(func.call(args), false, true);

## Reference

typedef boost::function< AnyReference(const AnyReferenceVector &)> DynamicFunction

### qi::AnyFunction Class Reference

#### Introduction

`More...`

    #include <qi/anyfunction.hpp>

#### Public Functions

``AnyFunction``()
``~AnyFunction``()
``AnyFunction``(const AnyFunction& b)
``AnyFunction``(FunctionTypeInterface* type, void* value)
AnyFunction& ``operator=``(const AnyFunction& b)
AnyReference ``call``(const AnyReferenceVector& args)
AnyReference ``call``(AnyReference arg1, const AnyReferenceVector& args)
AnyReference ``operator()``(const AnyReferenceVector& args)
template<typename R>
R ``call``(qi::AutoAnyReference p1)
template<typename R>
AnyReference ``operator()``(qi::AutoAnyReference p1)
const AnyFunction& ``dropFirstArgument``() const
const AnyFunction& ``replaceFirstArgument``(void* value) const
const AnyFunction& ``prependArgument``(void* value) const
std::vector<TypeInterface*> ``argumentsType``() const
TypeInterface* ``resultType``() const
Signature ``parametersSignature``(bool dropFirst) const
Signature ``returnSignature``() const
void ``swap``(AnyFunction& b)
``operator bool``() const
FunctionTypeInterface* ``functionType``() const
template<typename T>
AnyFunction ``from``(T&& f)

#### Public Static Functions

template<typename F>
AnyFunction ``from``(F&& func)
template<typename F, typename C>
AnyFunction ``from``(F func, C instance)
AnyFunction ``fromDynamicFunction``(DynamicFunction f)

#### Detailed Description

Represents a generic callable function. This class has value semantic.

#### Function Documentation

template<typename F>
static AnyFunction `qi::AnyFunction::``from`(F&& func)

template<typename F, typename C>

Brief:

Returns: | a AnyFunction binding instance to member function func

static AnyFunction `qi::AnyFunction::``from`(F func, C instance)

static AnyFunction `qi::AnyFunction::``fromDynamicFunction`(DynamicFunction f)

  Brief:

  Returns: | a AnyFunction that takes arguments as a list of unconverted AnyReference.

`qi::AnyFunction::``AnyFunction`()

`qi::AnyFunction::``~AnyFunction`()

`qi::AnyFunction::``AnyFunction`(const AnyFunction& b)

`qi::AnyFunction::``AnyFunction`(FunctionTypeInterface* type, void* value)

AnyFunction& `qi::AnyFunction::``operator=`(const AnyFunction& b)

AnyReference `qi::AnyFunction::``call`(const AnyReferenceVector& args)

  Brief:

  Parameters: | args – A list of unnamed arguments, each wrapped in an AnyReference for allowing introspection.

  Calls the function.

AnyReference `qi::AnyFunction::``call`(AnyReference arg1, const AnyReferenceVector& args)

  Call the function, reference must be destroy()ed.

AnyReference `qi::AnyFunction::``operator`(const AnyReferenceVector& args)

  Call the function, reference must be destroy()ed.

template<typename R>
R `qi::AnyFunction::``call`(qi::AutoAnyReference p1 = qi::AutoAnyReference()

  Call the function.

template<typename R>
AnyReference `qi::AnyFunction::``operator`(qi::AutoAnyReference p1 = qi::AutoAnyReference()

  Call the function, reference must be destroy()ed.

const AnyFunction& `qi::AnyFunction::``dropFirstArgument`()`const`

  Change signature, drop the first argument passed to call.

const AnyFunction& `qi::AnyFunction::``replaceFirstArgument`(void* value)`const`

  Replace first argument by value which must be storage for correct type.

const AnyFunction& `qi::AnyFunction::``prependArgument`(void* value)`const`

  Prepend extra argument value to argument list.

std::vector<TypeInterface*> `qi::AnyFunction::``argumentsType`()`const`

  Return expected argument types, taking transform into account.

TypeInterface* `qi::AnyFunction::``resultType`()`const`

Signature `qi::AnyFunction::``parametersSignature`(bool dropFirst = false)`const`

Signature `qi::AnyFunction::``returnSignature`()`const`

void `qi::AnyFunction::``swap`(AnyFunction& b)

`qi::AnyFunction::``operator` bool()`const`

FunctionTypeInterface* `qi::AnyFunction::``functionType`()`const`

template<typename T>
AnyFunction `qi::AnyFunction::``from`(T&& f)

Glossary Site map Index Support Contact Legal Notices