]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/poly_collection/detail/is_likely_stateless_lambda.hpp
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / boost / boost / poly_collection / detail / is_likely_stateless_lambda.hpp
CommitLineData
b32b8144
FG
1/* Copyright 2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/poly_collection for library home page.
7 */
8
9#ifndef BOOST_POLY_COLLECTION_DETAIL_IS_LIKELY_STATELESS_LAMBDA_HPP
10#define BOOST_POLY_COLLECTION_DETAIL_IS_LIKELY_STATELESS_LAMBDA_HPP
11
12#if defined(_MSC_VER)
13#pragma once
14#endif
15
16#include <type_traits>
17
18namespace boost{
19
20namespace poly_collection{
21
22namespace detail{
23
24/* Stateless lambda expressions have one (and only one) call operator and are
25 * convertible to a function pointer with the same signature. Non-lambda types
26 * could satisfy this too, hence the "likely" qualifier.
27 */
28
29template<typename T>
30struct has_one_operator_call_helper
31{
32 template<typename Q> static std::true_type test(decltype(&Q::operator())*);
33 template<typename> static std::false_type test(...);
34
35 using type=decltype(test<T>(nullptr));
36};
37
38template<typename T>
39using has_one_operator_call=typename has_one_operator_call_helper<T>::type;
40
41template<typename T>
42struct equivalent_function_pointer
43{
44 template<typename Q,typename R,typename... Args>
45 static auto helper(R (Q::*)(Args...)const)->R(*)(Args...);
46 template<typename Q,typename R,typename... Args>
47 static auto helper(R (Q::*)(Args...))->R(*)(Args...);
48
49 using type=decltype(helper(&T::operator()));
50};
51
52template<typename T,typename=void>
53struct is_likely_stateless_lambda:std::false_type{};
54
55template<typename T>
56struct is_likely_stateless_lambda<
57 T,
58 typename std::enable_if<has_one_operator_call<T>::value>::type
59>:std::is_convertible<
60 T,
61 typename equivalent_function_pointer<T>::type
62>{};
63
64} /* namespace poly_collection::detail */
65
66} /* namespace poly_collection */
67
68} /* namespace boost */
69
70#endif