165 lines
5.5 KiB
C++
165 lines
5.5 KiB
C++
// Copyright David Abrahams 2005.
|
|
// 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 ACTIV_BOOST_PARAMETER_BINDING_DWA200558_HPP
|
|
#define ACTIV_BOOST_PARAMETER_BINDING_DWA200558_HPP
|
|
|
|
#include <ActivBoost/parameter/aux_/void.hpp>
|
|
#include <ActivBoost/parameter/config.hpp>
|
|
|
|
#if defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
#include <ActivBoost/mp11/integral.hpp>
|
|
#include <ActivBoost/mp11/list.hpp>
|
|
#include <ActivBoost/mp11/utility.hpp>
|
|
#include <type_traits>
|
|
#else
|
|
#include <ActivBoost/mpl/bool.hpp>
|
|
#include <ActivBoost/mpl/if.hpp>
|
|
#include <ActivBoost/mpl/eval_if.hpp>
|
|
#include <ActivBoost/mpl/identity.hpp>
|
|
#include <ActivBoost/mpl/apply_wrap.hpp>
|
|
#include <ActivBoost/mpl/assert.hpp>
|
|
#include <ActivBoost/type_traits/is_same.hpp>
|
|
#endif
|
|
|
|
namespace Boost { namespace parameter {
|
|
|
|
// A metafunction that, given an argument pack, returns the reference type
|
|
// of the parameter identified by the given keyword. If no such parameter
|
|
// has been specified, returns Default
|
|
|
|
template <typename Parameters, typename Keyword, typename Default>
|
|
struct binding0
|
|
{
|
|
#if defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
using type = ::Boost::mp11::mp_apply_q<
|
|
typename Parameters::binding
|
|
, ::Boost::mp11::mp_list<Keyword,Default,::Boost::mp11::mp_true>
|
|
>;
|
|
|
|
static_assert(
|
|
::Boost::mp11::mp_if<
|
|
::std::is_same<Default,::Boost::parameter::void_>
|
|
, ::Boost::mp11::mp_if<
|
|
::std::is_same<type,::Boost::parameter::void_>
|
|
, ::Boost::mp11::mp_false
|
|
, ::Boost::mp11::mp_true
|
|
>
|
|
, ::Boost::mp11::mp_true
|
|
>::value
|
|
, "required parameters must not result in void_ type"
|
|
);
|
|
#else // !defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
typedef typename ::Boost::mpl::apply_wrap3<
|
|
typename Parameters::binding
|
|
, Keyword
|
|
, Default
|
|
, ::Boost::mpl::true_
|
|
>::type type;
|
|
|
|
ACTIV_BOOST_MPL_ASSERT((
|
|
typename ::Boost::mpl::eval_if<
|
|
::Boost::is_same<Default,::Boost::parameter::void_>
|
|
, ::Boost::mpl::if_<
|
|
::Boost::is_same<type,::Boost::parameter::void_>
|
|
, ::Boost::mpl::false_
|
|
, ::Boost::mpl::true_
|
|
>
|
|
, ::Boost::mpl::true_
|
|
>::type
|
|
));
|
|
#endif // ACTIV_BOOST_PARAMETER_CAN_USE_MP11
|
|
};
|
|
|
|
#if defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
template <typename Placeholder, typename Keyword, typename Default>
|
|
struct binding1
|
|
{
|
|
using type = ::Boost::mp11::mp_apply_q<
|
|
Placeholder
|
|
, ::Boost::mp11::mp_list<Keyword,Default,::Boost::mp11::mp_true>
|
|
>;
|
|
|
|
static_assert(
|
|
::Boost::mp11::mp_if<
|
|
::std::is_same<Default,::Boost::parameter::void_>
|
|
, ::Boost::mp11::mp_if<
|
|
::std::is_same<type,::Boost::parameter::void_>
|
|
, ::Boost::mp11::mp_false
|
|
, ::Boost::mp11::mp_true
|
|
>
|
|
, ::Boost::mp11::mp_true
|
|
>::value
|
|
, "required parameters must not result in void_ type"
|
|
);
|
|
};
|
|
#endif // ACTIV_BOOST_PARAMETER_CAN_USE_MP11
|
|
}} // namespace Boost::parameter
|
|
|
|
#include <ActivBoost/parameter/aux_/is_placeholder.hpp>
|
|
|
|
namespace Boost { namespace parameter {
|
|
|
|
template <
|
|
typename Parameters
|
|
, typename Keyword
|
|
, typename Default = ::Boost::parameter::void_
|
|
>
|
|
struct binding
|
|
#if !defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
: ::Boost::mpl::eval_if<
|
|
::Boost::parameter::aux::is_mpl_placeholder<Parameters>
|
|
, ::Boost::mpl::identity<int>
|
|
, ::Boost::parameter::binding0<Parameters,Keyword,Default>
|
|
>
|
|
#endif
|
|
{
|
|
#if defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
using type = typename ::Boost::mp11::mp_if<
|
|
::Boost::parameter::aux::is_mpl_placeholder<Parameters>
|
|
, ::Boost::mp11::mp_identity<int>
|
|
, ::Boost::mp11::mp_if<
|
|
::Boost::parameter::aux::is_mp11_placeholder<Parameters>
|
|
, ::Boost::parameter::binding1<Parameters,Keyword,Default>
|
|
, ::Boost::parameter::binding0<Parameters,Keyword,Default>
|
|
>
|
|
>::type;
|
|
#endif
|
|
};
|
|
}} // namespace Boost::parameter
|
|
|
|
#include <ActivBoost/parameter/aux_/result_of0.hpp>
|
|
|
|
namespace Boost { namespace parameter {
|
|
|
|
// A metafunction that, given an argument pack, returns the reference type
|
|
// of the parameter identified by the given keyword. If no such parameter
|
|
// has been specified, returns the type returned by invoking DefaultFn
|
|
template <typename Parameters, typename Keyword, typename DefaultFn>
|
|
struct lazy_binding
|
|
{
|
|
#if defined(ACTIV_BOOST_PARAMETER_CAN_USE_MP11)
|
|
using type = ::Boost::mp11::mp_apply_q<
|
|
typename Parameters::binding
|
|
, ::Boost::mp11::mp_list<
|
|
Keyword
|
|
, typename ::Boost::parameter::aux::result_of0<DefaultFn>::type
|
|
, ::Boost::mp11::mp_true
|
|
>
|
|
>;
|
|
#else
|
|
typedef typename ::Boost::mpl::apply_wrap3<
|
|
typename Parameters::binding
|
|
, Keyword
|
|
, typename ::Boost::parameter::aux::result_of0<DefaultFn>::type
|
|
, ::Boost::mpl::true_
|
|
>::type type;
|
|
#endif // ACTIV_BOOST_PARAMETER_CAN_USE_MP11
|
|
};
|
|
}} // namespace Boost::parameter
|
|
|
|
#endif // include guard
|
|
|