O
Size: a a a
O
D
ЗВ
Е
EK
tl::expected<image,fail_reason> get_cute_cat (const image& img) {
return crop_to_cat(img)
.and_then([](const image& img){
// code
})
.and_then([](...) {
// code
})
.map([](const ...) {
// code
})
.map([](const ...) {
// code
});
AF
tl::expected<image,fail_reason> get_cute_cat (const image& img) {
return crop_to_cat(img)
.and_then([](const image& img){
// code
})
.and_then([](...) {
// code
})
.map([](const ...) {
// code
})
.map([](const ...) {
// code
});
ЗВ
EK
Е
auto [x,y]
? Грубо говоря это сахар, чтоб не писать it->x it->y, у него в коде x\y приватные члены, там так не выйдет. ЗВ
AF
tl::expected<image,fail_reason> get_cute_cat (const image& img) {
return crop_to_cat(img)
.and_then([](const image& img){
// code
})
.and_then([](...) {
// code
})
.map([](const ...) {
// code
})
.map([](const ...) {
// code
});
Е
EK
fn file_double<P: AsRef<Path>>(file_path: P) -> Result<i32, String> {
File::open(file_path)
.map_err(|err| err.to_string())
.and_then(|mut file| {
let mut contents = String::new();
file.read_to_string(&mut contents)
.map_err(|err| err.to_string())
.map(|_| contents)
})
.and_then(|contents| {
contents.trim().parse::<i32>()
.map_err(|err| err.to_string())
})
.map(|n| 2 * n)
}
Не надо, по крайней мере, прописывать тип параметра каждый раз :))AF
fn file_double<P: AsRef<Path>>(file_path: P) -> Result<i32, String> {
File::open(file_path)
.map_err(|err| err.to_string())
.and_then(|mut file| {
let mut contents = String::new();
file.read_to_string(&mut contents)
.map_err(|err| err.to_string())
.map(|_| contents)
})
.and_then(|contents| {
contents.trim().parse::<i32>()
.map_err(|err| err.to_string())
})
.map(|n| 2 * n)
}
Не надо, по крайней мере, прописывать тип параметра каждый раз :))AF
AF
EK
AF
EK
auto result = [&]() -> std::optional<int> {
pre_code1();
if (!code1()) { return {}; }
pre_code2();
if (!code2()) { return {}; }
pre_code3();
if (!code3()) { return {}; }
return get();
}();
if (result) {
// success code
} else {
// fail code
}
AF