xtd 1.0.0
Loading...
Searching...
No Matches
division_expression.cpp

Shows how to use xtd::expressions::operator / expression.

#include <xtd/xtd>
struct foo {
int value;
friend auto operator <<(std::ostream& os, const foo& f) -> std::ostream& {return os << f.value;}
friend auto operator /(const foo& a, const foo& b) -> foo {return foo {a.value / b.value};}
};
auto main() -> int {
// auto div1 = [](auto&& a) {return a / 2;}
auto div1 = _ / 2;
println("div1 resul => {}", div1(84));
println();
// auto div2 = [](auto&& a, auto&& b) {return a / b;}
auto div2 = _1 / _2;
println("div2 resul => {}", div2(84, 2));
println("div2 resul => {}", div2(foo {84}, foo {2}));
// auto div3 = [](auto&& a, auto&& b, auto&& c) {return a / 2 / b / c;}
auto div3 = _1 / 2 / _2 / _3;
println("div3 resul => {}", div3(84, 7, 3));
}
// This code produces the following output :
//
// div1 resul => 42
//
// div2 resul => 42
// div2 resul => 42
//
// div3 resul => 2
//
constexpr auto _2
The xtd::expressions::_2 placeholder instance is second argument used by expression.
Definition args.hpp:117
constexpr auto _3
The xtd::expressions::_3 placeholder instance is third argument used by expression.
Definition args.hpp:142
constexpr auto _1
The xtd::expressions::_1 placeholder instance is first argument used by expression.
Definition args.hpp:92
auto println(FILE *file) -> void
Writes the current line terminator to the file output stream using the specified format information.
Definition println.hpp:14