C++ Logo

std-proposals

Advanced search

[std-proposals] requires(auto [a, b] = /* expr */){...}

From: 李 秋逸 <QiuyiLi1023_at_[hidden]>
Date: Wed, 8 Jan 2025 19:53:08 +0000
Hello everyone. Just as the title, there is no way to test whether an experession can be ructured bound. The title not looks like a good way and maybe the best idea will come up while discussion.

// These codes are just for learing,
// and the reason why I come up with this idea.
​template​<​class​ ​T​, ​class​ ​Alloc​>
class​ ​binary_tree​
{
    //...
    ​private:
 ​ template​<
 ​ ​class​ ​ValueGetter​,
 ​ ​class​ ​ChildrenGetter​,
 ​ class​ ​InitializeHandle
 ​ >
 ​ void​ ​recur_and_write_impl​(
 ​ edge_const_proxy p,
 ​ ValueGetter& vg,
 ​ ChildrenGetter& cg,
 ​ nitializeHandle& h
 ​ )
 ​ {
 ​ ​if​ (!p.​null​())
 ​ {
 ​ std::unreachable()​;
 ​ }
 ​ if​ (h)
 ​ {
 ​ emplace​(p, ​std::invoke​(vg, h));
 ​ auto​&& [lh, rh] = ​std::invoke​(cg, h);
 ​ auto​ [l, r] = p.​get_children​();
 ​ ​recur_and_write_impl​(l, vg, cg, lh);
 ​ recur_and_write_impl​(r, vg, cg, rh);
 ​ }
 ​ }
    public:
    ​binary_tree ​recur_and_write​(
 ​ edge_const_proxy p,
 ​ ValueGetter vg,
 ​ ChildrenGetter cg,
 ​ InitializeHandle h
 ​ )
 ​ {
 ​ binary_tree ret{ ​cut​(p) };
 ​ ​recur_and_write_impl​(p, vg, cg, h);
 ​ return​ ret;
 ​ }
};

The requirement of recur_and_write maybe
requires(auto&& [ lh, rh ] = std::invoke(std::declval<ChildrenGetter>(), std::declval<InitializeHandle>()))
{
    (bool)std::declval<InitializeHandle>();
}

获取Outlook for Android<https://aka.ms/AAb9ysg>

Received on 2025-01-08 19:53:15