LeechCraft  0.6.70-13729-g7046a9d2a7
Modular cross-platform feature rich live environment.
dropargs.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include "typelist.h"
33 
34 namespace LC
35 {
36 namespace Util
37 {
38  namespace detail
39  {
40  template<typename F, template<typename...> class List, typename... Args>
41  constexpr List<Args...> GetInvokablePartImpl (int, List<Args...>, typename std::result_of<F (Args...)>::type* = nullptr)
42  {
43  return {};
44  }
45 
46  template<typename F, template<typename...> class List>
47  constexpr Typelist<> GetInvokablePartImpl (float, List<>)
48  {
49  return {};
50  }
51 
52  template<typename F, typename List>
53  struct InvokableType;
54 
55  template<typename F, template<typename...> class List, typename... Args>
57  {
58  return {};
59  }
60 
61  template<typename F, typename List>
62  struct InvokableType
63  {
64  using RetType_t = decltype (GetInvokablePartImpl<F> (0, List {}));
65  };
66 
67  template<typename F, typename... Args>
68  constexpr auto GetInvokablePart () -> decltype (GetInvokablePartImpl<F> (0, Typelist<Args...> {}))
69  {
70  return {};
71  }
72 
73  template<template<typename...> class List, typename... Args>
74  constexpr size_t Length (List<Args...>)
75  {
76  return sizeof... (Args);
77  }
78 
79  template<typename T>
80  struct Dumbifier
81  {
82  using Type_t = T;
83  };
84 
85  template<typename T>
86  using Dumbify = typename Dumbifier<T>::Type_t;
87 
88  template<typename F, typename List>
90 
91  template<typename F, template<typename...> class List, typename... Args>
92  struct InvokableResGetter<F, List<Args...>>
93  {
94  using RetType_t = std::result_of_t<F (Args...)>;
95  };
96 
97  template<typename F>
98  class Dropper
99  {
100  F F_;
101  public:
102  Dropper (const F& f)
103  : F_ (f)
104  {
105  }
106 
107  template<typename... Args>
108  auto operator() (Args... args) -> typename InvokableResGetter<F, decltype (GetInvokablePart<F, Args...> ())>::RetType_t
109  {
110  auto invokableList = GetInvokablePart<F, Args...> ();
111  auto ignoreList = Drop<Length (decltype (invokableList) {})> (Typelist<Args...> {});
112  return Invoke (invokableList, ignoreList, args...);
113  }
114  private:
115  template<typename... InvokableArgs, typename... Rest>
116  auto Invoke (Typelist<InvokableArgs...>, Typelist<Rest...>, Dumbify<InvokableArgs>... args, Dumbify<Rest>...) -> std::result_of_t<F (InvokableArgs...)>
117  {
118  return F_ (std::forward<InvokableArgs> (args)...);
119  }
120  };
121  }
122 
123  template<typename F>
125  {
126  return detail::Dropper<F> { f };
127  }
128 }
129 }
typename Dumbifier< T >::Type_t Dumbify
Definition: dropargs.h:86
constexpr auto GetInvokablePart() -> decltype(GetInvokablePartImpl< F >(0, Typelist< Args... >
Definition: dropargs.h:68
decltype(GetInvokablePartImpl< F >(0, List {})) RetType_t
Definition: dropargs.h:64
detail::Dropper< F > DropArgs(const F &f)
Definition: dropargs.h:124
constexpr size_t Length(List< Args... >)
Definition: dropargs.h:74
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptr > > f
Definition: oral.h:955
auto operator()(Args... args) -> typename InvokableResGetter< F, decltype(GetInvokablePart< F, Args... >())>::RetType_t
Definition: dropargs.h:108
constexpr List< Args... > GetInvokablePartImpl(int, List< Args... >, typename std::result_of< F(Args...)>::type *=nullptr)
Definition: dropargs.h:41
constexpr detail::DropImpl< N, List< Args... > >::Result_t Drop(List< Args... >)
Definition: typelist.h:77
std::conditional_t< std::is_same_v< detail::RetTypeRaw_t< F >, detail::ReturnsVoid >, void, detail::RetTypeRaw_t< F > > RetType_t
Definition: typegetter.h:77
Definition: constants.h:35