Wie implementiert man die Bindung selbst?
大家讲道理
大家讲道理 2017-06-15 09:23:57
0
1
813
//---------------------------1-------------------
    template<int _Nx>
    struct _Ph
    {    // placeholder
    };

//-----------------2-------------------------------

// TEMPLATE FUNCTION bind (explicit return type)
template<class _Ret,
    class _Fx,
    class... _Types> inline
    _Binder<_Ret, _Fx, _Types...> bind(_Fx&& _Func, _Types&&... _Args)
    {    // bind a callable object with an explicit return type
    return (_Binder<_Ret, _Fx, _Types...>(
        _STD forward<_Fx>(_Func), _STD forward<_Types>(_Args)...));
    }

///--------------------------3------------------------

    // PLACEHOLDER ARGUMENTS
        namespace placeholders {    // placeholders
constexpr _Ph<1> _1{};
constexpr _Ph<2> _2{};
constexpr _Ph<3> _3{};
constexpr _Ph<4> _4{};
constexpr _Ph<5> _5{};
constexpr _Ph<6> _6{};
constexpr _Ph<7> _7{};
constexpr _Ph<8> _8{};
constexpr _Ph<9> _9{};
constexpr _Ph<10> _10{};
constexpr _Ph<11> _11{};
constexpr _Ph<12> _12{};
constexpr _Ph<13> _13{};
constexpr _Ph<14> _14{};
constexpr _Ph<15> _15{};
constexpr _Ph<16> _16{};
constexpr _Ph<17> _17{};
constexpr _Ph<18> _18{};
constexpr _Ph<19> _19{};
constexpr _Ph<20> _20{};
        }    // namespace placeholders

Ich verstehe den Code in der Mitte nicht. Wie wird er mit Teil 3 implementiert? Wer kann eine einfachere Bindung schreiben, danke.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(1)
三叔

用伪代码写看起来可以是这样(省略转发和元编程细节):

template <size_t i, ...>
auto get(...) {
  if (binding_argument_type[i] == placeholder)
    return calling_argument[the_index_in_the_placeholder];
  else
    return binding_argument[i];
}

template <class Fn, class... binding_argument_type>
auto bind(Fn fn, binding_argument_type... binding_argument) {
  return [...](auto... calling_argument) {
    return fn(get<index>(binding_argument..., calling_argument...)...);
  };
}
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!