Utility Rack
Loading...
Searching...
No Matches
forward_capture.hpp File Reference

A utility to perfectly forward function template parameters in lambda captures. More...

#include <tuple>
#include <utility>
Include dependency graph for forward_capture.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CHOPS_FWD(...)
 
#define CHOPS_FWD_CAPTURE(...)
 

Functions

template<typename... Ts>
auto chops::detail::fwd_capture (Ts &&... xs)
 
template<typename T >
decltype(auto) chops::access (T &&x)
 

Detailed Description

A utility to perfectly forward function template parameters in lambda captures.

This code is copied from Vittorio Romeo's blog at https://vittorioromeo.info/, specifically: https://vittorioromeo.info/index/blog/capturing_perfectly_forwarded_objects_in_lambdas.html.

It is not easy to perfectly forward function template parameters in a lambda capture. In particular, a function object passed through a forwarding reference should be passed as either an rvalue or lvalue reference, depending on what was passed in (which of course is what a forwarding reference is all about). Capturing and preserving the forwarding reference in a lambda is complicated (more so than it should be). This utility provides a wrapper class, which (as in so many software design problems) solves the problem with a layer of indirection.

Authors
Vittorio Romeo, Cliff Green

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Macro Definition Documentation

◆ CHOPS_FWD

#define CHOPS_FWD ( ...)
Value:
std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)

◆ CHOPS_FWD_CAPTURE

#define CHOPS_FWD_CAPTURE ( ...)
Value:
chops::detail::fwd_capture(CHOPS_FWD(__VA_ARGS__))