1/*=============================================================================
2 Copyright (c) 2015 Paul Fultz II
3 callable_base.h
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6==============================================================================*/
7
8#ifndef BOOST_HOF_GUARD_CALLABLE_BASE_H
9#define BOOST_HOF_GUARD_CALLABLE_BASE_H
10
11#include <boost/hof/detail/delegate.hpp>
12#include <boost/hof/detail/result_of.hpp>
13#include <boost/hof/apply.hpp>
14
15#ifndef BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS
16#if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7)
17#define BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS 0
18#else
19#define BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS 1
20#endif
21#endif
22
23namespace boost { namespace hof { namespace detail {
24
25template<class F>
26struct non_class_function
27{
28 F f;
29 BOOST_HOF_DELEGATE_CONSTRUCTOR(non_class_function, F, f)
30
31 template<class... Ts>
32 constexpr BOOST_HOF_SFINAE_RESULT(apply_f, id_<F>, id_<Ts>...)
33 operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
34 (
35 boost::hof::apply(f, BOOST_HOF_FORWARD(Ts)(xs)...)
36 );
37};
38
39template<class F>
40struct callable_base_type
41: std::conditional<(BOOST_HOF_IS_CLASS(F) && !BOOST_HOF_IS_FINAL(F) && !BOOST_HOF_IS_POLYMORPHIC(F)), F, non_class_function<F>>
42{};
43
44#if BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS
45template<class F>
46using callable_base = typename callable_base_type<F>::type;
47#else
48template<class F>
49struct callable_base
50: callable_base_type<F>::type
51{
52 typedef typename callable_base_type<F>::type base;
53 BOOST_HOF_INHERIT_CONSTRUCTOR(callable_base, base)
54};
55
56template<class F>
57struct callable_base_type<callable_base<F>>
58: callable_base_type<F>
59{};
60
61#endif
62
63}}} // namespace boost::hof
64
65#endif
66

source code of boost/libs/hof/include/boost/hof/detail/callable_base.hpp