xtd 1.0.0
Loading...
Searching...
No Matches
add_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 add1 = [](auto&& a) {return a + 10;}
auto add1 = _ + 10;
println("add1 resul => {}", add1(42));
println();
//auto add2 = [](auto&& a, auto&& b) {return a + b;}
auto add2 = _1 + _2;
println("add2 resul => {}", add2(42, 10));
println("add2 resul => {}", add2("Hello, "_s, "world!"));
println("add2 resul => {}", add2(date_time {2026, 4, 20, 21, 12, 36}, 7_min + 24_s));
println("add2 resul => {}", add2(foo {42}, foo {10}));
//auto add3 = [](auto&& a, auto&& b, auto&& c) {return a + 10 + b + c;}
auto add3 = _1 + 10 + _2 + _3;
println("add3 resul => {}", add3(22, 18, 2));
}
// This code produces the following output :
//
// add1 resul => 52
//
// add2 resul => 52
// add2 resul => Hello, world!
// add2 resul => 4/20/2026 9:20:00 PM
// add2 resul => 52
//
// add3 resul => 52
//
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