C++ Library Extensions 2022.12.09
To help learn modern C++ programming
017-expression-fold.cpp
Go to the documentation of this file.
1#include <tpf_output.hpp>
2
4auto nl = tpf::nl;
6
7template<typename Type1, typename Type2, typename... Types>
8auto Divide(Type1 dividend, Type2 divisor, Types... args)
9{
10 auto divisors =
11 std::vector<Type1>{ static_cast<Type1>(args)... };
12
13 dividend /= divisor;
14
15 for(auto& d : divisors)
16 dividend /= d;
17
18 return dividend;
19}
20
22{
23 stream << "divide 2*3*5 with 3, 5 = "
24 << Divide(2*3*5, 3, 5) << endl;
25}
26
27template<typename Type1, typename... Types>
28auto divide_fold(Type1 dividend, Types... args)
29{
30 return (dividend / ... / args);
31}
32
34{
35 stream << "divide 2*3*5 with 3, 5 = "
36 << divide_fold(2*3*5, 3, 5) << endl;
37}
38
39int main()
40{
41 // test_divide();
43}
auto Divide(Type1 dividend, Type2 divisor, Types... args)
void test_divide()
void test_divide_fold()
tpf::sstream stream
auto endl
auto divide_fold(Type1 dividend, Types... args)
auto nl
int main()
constexpr auto endl
Definition: tpf_output.hpp:973
constexpr auto nl
Definition: tpf_output.hpp:971
Stream output operators << are implemented.