Edit: /usr/include/boost/hof/implicit.hpp (4041B)
/*=============================================================================
Copyright (c) 2012 Paul Fultz II
implicit.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_IMPLICIT_H
#define BOOST_HOF_GUARD_FUNCTION_IMPLICIT_H
/// implicit
/// ========
///
/// Description
/// -----------
///
/// The `implicit` adaptor is a static function adaptor that uses the type
/// that the return value can be converted to, in order to determine the type
/// of the template parameter. In essence, it will deduce the type for the
/// template parameter using the type of variable the result is assigned to.
/// Since it is a static function adaptor, the function must be default
/// constructible.
///
/// Synopsis
/// --------
///
/// template
class F>
/// class implicit;
///
/// Semantics
/// ---------
///
/// assert(T(implicit()(xs...)) == F()(xs...));
///
/// Requirements
/// ------------
///
/// F must be a template class, that is a:
///
/// * [ConstFunctionObject](ConstFunctionObject)
/// * DefaultConstructible
///
/// Example
/// -------
///
/// #include
/// #include
/// using namespace boost::hof;
///
/// template
/// struct auto_caster
/// {
/// template
/// T operator()(U x)
/// {
/// return T(x);
/// }
/// };
///
/// static constexpr implicit auto_cast = {};
///
/// struct auto_caster_foo
/// {
/// int i;
/// explicit auto_caster_foo(int i_) : i(i_) {}
///
/// };
///
/// int main() {
/// float f = 1.5;
/// int i = auto_cast(f);
/// auto_caster_foo x = auto_cast(1);
/// assert(1 == i);
/// assert(1 == x.i);
/// }
///
#include
#include
namespace boost { namespace hof { namespace detail {
template
struct is_implicit_callable
: std::false_type
{};
#if BOOST_HOF_NO_EXPRESSION_SFINAE
template
struct is_implicit_callable>::type, X>::value
>::type>
: std::true_type
{};
#else
template
struct is_implicit_callable()(std::declval())), X>::value
>::type>
: std::true_type
{};
#endif
}
template class F>
struct implicit
{
template
struct invoker
{
Pack p;
constexpr invoker(Pack pp) BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(Pack, Pack&&)
: p(boost::hof::move(pp))
{}
template, Pack, X>::value>::type>
constexpr operator X() const BOOST_HOF_NOEXCEPT(noexcept(p(F())))
{
return p(F());
}
#if !(defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7)
invoker (const invoker&) = delete;
invoker& operator= (const invoker&) = delete;
private:
friend struct implicit;
invoker (invoker&&) = default;
#endif
};
struct make_invoker
{
template
constexpr invoker operator()(Pack p) const BOOST_HOF_NOEXCEPT(noexcept(invoker(boost::hof::move(p))))
{
return invoker(boost::hof::move(p));
}
};
template
constexpr auto operator()(Ts&&... xs) const
BOOST_HOF_RETURNS
(
BOOST_HOF_RETURNS_CONSTRUCT(make_invoker)()(boost::hof::pack_basic(BOOST_HOF_FORWARD(Ts)(xs)...))
);
};
}} // namespace boost::hof
#endif