funcy  1.6.1
generate.h
1 #pragma once
2 
3 #include <funcy/concepts.h>
4 #include <funcy/constant.h>
5 #include <funcy/operations.h>
6 #include <funcy/variable.h>
7 
8 #include <concepts>
9 #include <type_traits>
10 #include <utility>
11 
12 namespace funcy
13 {
20  template < Function F, Function G >
21  auto operator+( F&& f, G&& g )
22  {
23  return mathop::Sum( std::forward< F >( f ), std::forward< G >( g ) );
24  }
25 
32  template < class F, Function G >
33  auto operator+( F&& f, G&& g )
34  {
35  return mathop::Sum( constant( std::forward< F >( f ) ), std::forward< G >( g ) );
36  }
37 
44  template < Function F, class G >
45  auto operator+( F&& f, G&& g )
46  {
47  return mathop::Sum( std::forward< F >( f ), constant( std::forward< G >( g ) ) );
48  }
49 
56  template < Function F, Function G >
57  auto operator*( F&& f, G&& g )
58  {
59  return mathop::Product( std::forward< F >( f ), std::forward< G >( g ) );
60  }
61 
68  template < class F, Function G >
69  auto operator*( F&& f, G&& g )
70  {
71  return mathop::Product( constant( std::forward< F >( f ) ), std::forward< G >( g ) );
72  }
73 
80  template < Arithmetic F, Function G >
81  auto operator*( F&& f, G&& g )
82  {
83  return mathop::Scale( std::forward< F >( f ), std::forward< G >( g ) );
84  }
85 
92  template < Function F, class G >
93  auto operator*( F&& f, G&& g )
94  {
95  return mathop::Product( std::forward< F >( f ), constant( std::forward< G >( g ) ) );
96  }
97 
104  template < Function F, Arithmetic G >
105  auto operator*( F&& f, G&& g )
106  {
107  return mathop::Scale( std::forward< G >( g ), std::forward< F >( f ) );
108  }
109 
116  template < Function F, Function G >
117  auto dot( F&& f, G&& g )
118  {
119  return mathop::Dot< std::decay_t< F >, std::decay_t< G > >( std::forward< F >( f ),
120  std::forward< G >( g ) );
121  }
122 
129  template < class F, Function G >
130  auto dot( F&& f, G&& g )
131  {
132  return mathop::Dot< std::decay_t< F >, std::decay_t< G > >(
133  constant( std::forward< F >( f ) ), std::forward< G >( g ) );
134  }
135 
142  template < Function F, class G >
143  auto dot( F&& f, G&& g )
144  {
145  return mathop::Dot< std::decay_t< F >, std::decay_t< G > >(
146  std::forward< F >( f ), constant( std::forward< G >( g ) ) );
147  }
148 
155  template < Function F >
156  auto squared( F&& f )
157  {
158  return mathop::Squared< std::decay_t< F > >( std::forward< F >( f ) );
159  }
160 
167  template < Function F, Function G >
168  auto operator-( F&& f, G&& g )
169  {
170  return mathop::Subtraction( std::forward< F >( f ), std::forward< G >( g ) );
171  }
172 
179  template < class F, Function G >
180  auto operator-( F&& f, G&& g )
181  {
182  return mathop::Subtraction( constant( std::forward< F >( f ) ), std::forward< G >( g ) );
183  }
184 
191  template < Function F, class G >
192  auto operator-( F&& f, G&& g )
193  {
194  return mathop::Subtraction( std::forward< F >( f ), constant( std::forward< G >( g ) ) );
195  }
196 
204  template < class F, class G >
205  auto operator/( F&& f, G&& g ) requires( requires( G g ) {
206  {
207  g()
208  }
209  ->std::convertible_to< double >;
210  } )
211  {
212  return std::forward< F >( f ) * pow< -1 >( std::forward< G >( g ) );
213  }
214 
222  template < class F, Arithmetic G >
223  auto operator/( F&& f, G g )
224  {
225  return std::forward< F >( f ) * constant( 1 / g );
226  }
227 } // namespace funcy
Subtraction of functions of type F and G.
Definition: subtraction.h:20
auto dot(F &&f, G &&g)
overload of "dot"-function for the generation of functions.
Definition: generate.h:117
Dot of functions of type F and G.
Definition: dot.h:21
Sum of functions of type F and G.
Definition: sum.h:20
Product of functions of type F and G.
Definition: product.h:21
Main namespace of the funcy library.
constexpr auto constant(Arg &&x) noexcept((std::is_rvalue_reference_v< Arg > &&std::is_nothrow_move_constructible_v< Arg >)||(std::is_lvalue_reference_v< Arg > &&std::is_nothrow_copy_constructible_v< Arg >))
Wrap a constant.
Definition: constant.h:51
auto operator+(F &&f, G &&g)
overload of "+"-operator for the generation of functions.
Definition: generate.h:21
Squared function .
Definition: squared.h:22
auto operator/(F &&f, G &&g) requires(requires(G g)
overload of "/"-operator for the generation of functions.
Definition: generate.h:205
auto operator-(F &&f, G &&g)
overload of "-"-operator for the generation of functions.
Definition: generate.h:168
auto squared(F &&f)
Generate squared function.
Definition: generate.h:156
Scaling of some function with a double .
Definition: scale.h:20
auto operator*(F &&f, G &&g)
overload of "*"-operator for the generation of functions.
Definition: generate.h:57