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

Shows how to use xtd::expressions::expression::add expression.

#include <xtd/xtd>
struct foo {
int value;
auto operator +(const foo& v) -> foo {return foo {value + v.value};}
};
auto main() -> int {
//auto add = [](auto&& _1, auto&& _2) {return _1 + _2;}
auto add = _1 + _2;
println(R"(add(40, 20)) = {})", add(40, 20));
println(R"(add("Barry "_s, "Allen"_s) = {})", add("Barry "_s, "Allen"_s));
println(R"(add(date_time {2026, 4, 20, 21, 12, 36}, 7_min + 24_s) = {})", add(date_time {2026, 4, 20, 21, 12, 36}, 7_min + 24_s));
println(R"(add(foo {{50}}, foo {{30}}) = {})", add(foo {50}, foo {30}).value);
}
// This code produces the following output :
//
// add(40, 20)) = 60
// add("Barry "_s, "Allen"_s) = Barry Allen
// add(date_time , 7_min + 24_s) = 4/20/2026 9:20:00 PM
// add(foo {50}, foo {30}) = 80
@ add
The Add key.
Definition console_key.hpp:170
auto println(FILE *file) -> void
Writes the current line terminator to the file output stream using the specified format information.
Definition println.hpp:15