Alien-boost-mini
view release on metacpan or search on metacpan
include/boost/hof/lambda.hpp view on Meta::CPAN
/*=============================================================================
Copyright (c) 2014 Paul Fultz II
lambda.h
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#ifndef BOOST_HOF_GUARD_FUNCTION_LAMBDA_H
#define BOOST_HOF_GUARD_FUNCTION_LAMBDA_H
/// BOOST_HOF_STATIC_LAMBDA
/// =================
///
/// Description
/// -----------
///
/// The `BOOST_HOF_STATIC_LAMBDA` macro allows initializing non-capturing lambdas at
/// compile-time in a `constexpr` expression.
///
/// Example
/// -------
///
/// #include <boost/hof.hpp>
/// #include <cassert>
///
/// const constexpr auto add_one = BOOST_HOF_STATIC_LAMBDA(int x)
/// {
/// return x + 1;
/// };
///
/// int main() {
/// assert(3 == add_one(2));
/// }
///
/// BOOST_HOF_STATIC_LAMBDA_FUNCTION
/// ==========================
///
/// Description
/// -----------
///
/// The `BOOST_HOF_STATIC_LAMBDA_FUNCTION` macro allows initializing a global
/// function object that contains non-capturing lambdas. It also ensures that
/// the global function object has a unique address across translation units.
/// This helps prevent possible ODR-violations.
///
/// By default, all functions defined with `BOOST_HOF_STATIC_LAMBDA_FUNCTION` use
/// the `boost::hof::reveal` adaptor to improve error messages.
///
/// Example
/// -------
///
/// #include <boost/hof.hpp>
/// #include <cassert>
///
/// BOOST_HOF_STATIC_LAMBDA_FUNCTION(add_one) = [](int x)
/// {
/// return x + 1;
/// };
/// int main() {
/// assert(3 == add_one(2));
/// }
///
#include <boost/hof/config.hpp>
// TODO: Move this to a detail header
#if !BOOST_HOF_HAS_CONSTEXPR_LAMBDA || !BOOST_HOF_HAS_INLINE_LAMBDAS
#include <type_traits>
#include <utility>
#include <boost/hof/detail/result_of.hpp>
#include <boost/hof/reveal.hpp>
#include <boost/hof/detail/constexpr_deduce.hpp>
#include <boost/hof/function.hpp>
#ifndef BOOST_HOF_REWRITE_STATIC_LAMBDA
#ifdef _MSC_VER
#define BOOST_HOF_REWRITE_STATIC_LAMBDA 1
#else
#define BOOST_HOF_REWRITE_STATIC_LAMBDA 0
#endif
#endif
namespace boost { namespace hof {
namespace detail {
template<class F>
struct static_function_wrapper
{
// Default constructor necessary for MSVC
constexpr static_function_wrapper()
{}
static_assert(BOOST_HOF_IS_EMPTY(F), "Function or lambda expression must be empty");
struct failure
: failure_for<F>
{};
template<class... Ts>
const F& base_function(Ts&&...) const
( run in 0.524 second using v1.01-cache-2.11-cpan-7e98afdb40f )