deal.II version GIT relicensing-2069-gd7d5dbb18d 2024-11-01 22:40:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Functions
std_cxx20 Namespace Reference

Namespaces

namespace  ranges
 

Classes

struct  type_identity
 

Typedefs

template<class T >
using type_identity_t = typename type_identity< T >::type
 

Functions

template<typename F , typename... BoundArgs>
decltype(auto) bind_front (F &&f, BoundArgs &&...bound_args)
 

Detailed Description

deal.II currently only requires a C++17-conforming compiler, but there are a number of functions and classes from the C++20 standard that are easy to provide also in case the compiler only supports C++17. These are collected in the current namespace.

One example is the std::ranges::iota_view class that was introduced to C++ starting with the C++20 standard. It is used as the return type for the ReferenceCell::face_indices(), ReferenceCell::vertex_indices(), and FEValuesBase::quadrature_point_indices() functions, among others, to support range-based for loops (see deal.II and Modern C++ standards for examples of range-based for loops, as well as the documentation of the functions mentioned above).

There are other small additions in this namespace that allow us to use C++20 features at this point already, even though we don't require a C++20-compliant compiler.

Note
If the compiler in use actually does support C++20, then the contents of this namespace are simply imported classes and functions from namespace std. That is, we fall back to what the compiler provides, rather than our own implementations.

Typedef Documentation

◆ type_identity_t

template<class T >
using std_cxx20::type_identity_t = typedef typename type_identity<T>::type

Definition at line 95 of file type_traits.h.

Function Documentation

◆ bind_front()

template<typename F , typename... BoundArgs>
decltype(auto) std_cxx20::bind_front ( F &&  f,
BoundArgs &&...  bound_args 
)

This function generates a forwarding call wrapper to the function f which has its first n arguments bound to the n arguments passed in bound_args. The implementation is an approximation to the functionality provided by std::bind_front, see https://en.cppreference.com/w/cpp/utility/functional/bind_front.

This function allows to remove boilerplate in user code. Often functions in the deal.II library take a std::function object as an argument. While you can pass many different types of callable objects to a std::function directly, you cannot pass a pointer to a member function. Instead you can use the present function to create a compatible callable on-the-fly which can be assigned to std::function. This is demonstrated in the following example:

// An exemplary function that takes an std::function as argument.
void example_function(const std::function<int(double)>& fn);
class MyClass
{
public:
void do_something()
{
// Pass the member function
example_function(
std_cxx20::bind_front(&MyClass::my_function, this));
}
private:
// This function has a signature which is compatible with the function
// that is expected by example_function().
int my_function(double);
};
decltype(auto) bind_front(F &&f, BoundArgs &&...bound_args)
Definition functional.h:121

Definition at line 121 of file functional.h.