PStack  2.0
Stack trace printer for MSVC and GCC binaries
psystem::shared_library::loaded_function< T, is_void_ref > Struct Template Reference

Encapsulate a loaded function's address into a callable functor. More...

#include <shared_library.hpp>

Inheritance diagram for psystem::shared_library::loaded_function< T, is_void_ref >:
Collaboration diagram for psystem::shared_library::loaded_function< T, is_void_ref >:

Public Member Functions

 loaded_function (FARPROC proc)
 Construct a loaded_function from a function pointer. More...
 
template<typename... Args>
auto operator() (Args &&...args) -> decltype(std::declval< T >()(std::forward< Args >(args)...))
 Invoke the library function. More...
 
- Public Member Functions inherited from psystem::shared_library::loaded_function_base< T >
 loaded_function_base (FARPROC proc)
 Construct a loaded_function from a function pointer. More...
 
void retarget (FARPROC proc) noexcept
 Re-assign a function pointer to this functor instance. More...
 
T * get_ptr () const noexcept
 Access the function pointer contained here directly. More...
 

Additional Inherited Members

- Protected Attributes inherited from psystem::shared_library::loaded_function_base< T >
T * m_function
 The function pointer that may be invoked.
 

Detailed Description

template<typename T, typename is_void_ref = has_void_return_type<T>>
struct psystem::shared_library::loaded_function< T, is_void_ref >

Encapsulate a loaded function's address into a callable functor.

This functor automagically determines the return type of the function passed to it, and returns the data accordingly. Also, it uses "perfect forwarding" to hand all arguments from the caller to the underlying loaded function.

Note
This work can easily be done with std::function, but this implementation takes much less space, and function may even introduce a vtable, which is far too heavy.
Template Parameters
TThe function signature that will be used to store the wrapped function.
is_void_refUsed to determine if the loaded_function instance should provide a function with a void return type. Unless you wrap a non-void function, and explicitly want to force it into a void return type, do not specify this. The metafunction, has_void_return_type will determine the correct return automatically.
Author
Matt Bisson
Date
19 November, 2015
Since
PSystem 2.0
Version
PSystem 2.0

Constructor & Destructor Documentation

template<typename T , typename is_void_ref = has_void_return_type<T>>
psystem::shared_library::loaded_function< T, is_void_ref >::loaded_function ( FARPROC  proc)
inline

Construct a loaded_function from a function pointer.

Parameters
[in]procThe proceedure's address. Type safety is out the window; we must trust you. This may be nullptr.
Todo:
I would rather inherit the CTOR with "using base::base", but MSVC apparently does not support this.

Member Function Documentation

template<typename T , typename is_void_ref = has_void_return_type<T>>
template<typename... Args>
auto psystem::shared_library::loaded_function< T, is_void_ref >::operator() ( Args &&...  args) -> decltype(std::declval<T>()(std::forward<Args>(args)...))
inline

Invoke the library function.

Template Parameters
ArgsThe argument pack should match the declared function signature.
Parameters
[in]argsZero or more arguments to be forwarded to the underlying function. Check the actual function signature and documentation for details.
Returns
Whatever the underlying function returns.
Exceptions
Whateverthe underlying function throws.
Todo:
Determine the noexcept value when MSVC supports it.

The documentation for this struct was generated from the following file: