N-ary functions#

#include <heyoka/func.hpp>

The func_base class#

class func_base#

This is the base class of all functions implemented in the expression system.

It provides a common interface for constructing functions and accessing their arguments.

explicit func_base(std::string name, std::vector<expression> args)#

Constructor from name and arguments.

Parameters:
  • name – the function name.

  • args – the function arguments.

Exception:

any exceptions raised by copying the name or the arguments.

Throws:

std::invalid_argument – if name is empty.

func_base(const func_base&)#
func_base(func_base&&) noexcept#
func_base &operator=(const func_base&)#
func_base &operator=(func_base&&) noexcept#
~func_base()#

func_base is copy/move constructible, copy/move assignable and destructible.

Exception:

any exception thrown by the copy constructor/copy assignment operator the function’s name or arguments.

[[nodiscard]] const std::string &get_name() const noexcept#

Name getter.

Returns:

a reference to the function’s name.

[[nodiscard]] const std::vector<expression> &args() const noexcept#

Arguments getter.

Returns:

a reference to the function’s arguments.

The func class#

class func#

This class is used to represent functions in the expression system.

func is a polymorphic wrapper that can be constructed from any object satisfying certain conceptual requirements. We refer to such objects as user-defined functions, or UDFs (see the is_udf concept).

The polymorphic wrapper is implemented internally via std::shared_ptr, and thus func employs reference semantics: copy construction and copy assignment do not throw, and they are constant-time operations.

Note

At this time, the func API is still in flux and as such it is largely undocumented. Please refer to the source code if you need to understand the full API.

func()#

Default constructor.

The default constructor will initialise this func object with an implementation-defined UDF.

Exception:

any exception thrown by memory allocation failures.

template<typename T>
requires (!std::same_as<func, std::remove_cvref_t<T>>) && is_udf<std::remove_cvref_t<T>>
explicit func(T &&x)#

Generic constructor.

This constructor will initialise this with the user-defined function x.

Exception:

any exception thrown by memory allocation failures or by the copy/move constructor of the user-defined function x.

func(const func&) noexcept#
func(func&&) noexcept#
func &operator=(const func&) noexcept#
func &operator=(func&&) noexcept#
~func()#

func is copy/move constructible, copy/move assignable and destructible.

The only valid operations on a moved-from func are destruction and copy/move assignment.

[[nodiscard]] const std::string &get_name() const noexcept#

Name getter.

This getter will invoke func_base::get_name() on the internal UDF.

Returns:

a reference to the function’s name.

[[nodiscard]] const std::vector<expression> &args() const noexcept#

Arguments getter.

This getter will invoke func_base::args() on the internal UDF.

Returns:

a reference to the function’s arguments.

Concepts#

template<typename T>
concept is_udf = std::default_initializable<T> && std::movable<T> && std::copyable<T> && std::derived_from<T, func_base>#

User-defined function concept.

This concept enumerates the minimum requirements of user-defined functions (UDFs), that is, objects that can be used to construct a func.