// Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include namespace Building { class NestId {}; template class IdAndArg { public: IdAndArg(Id, const Arg &arg) : arg(arg) {} const Arg arg; // FIXME: Could be const &, but this would currently break bindTo(). }; // The main dispatcher void doit(auto x, auto id, auto p); template class BuilderItem { public: // Property setter template BuilderItem(IdAndArg && idarg) : apply([&idarg](X *x) { doit(x, Id{}, idarg.arg); }) {} // Nested child object template BuilderItem(Inner && p) : apply([&p](X *x) { doit(x, NestId{}, std::forward(p)); }) {} const std::function apply; }; #define QTC_DEFINE_BUILDER_SETTER(name, setter) \ class name##_TAG {}; \ template \ inline auto name(Args &&...args) { \ return Building::IdAndArg{name##_TAG{}, std::tuple{std::forward(args)...}}; \ } \ template \ inline void doit(L *x, name##_TAG, const std::tuple &arg) { \ std::apply(&L::setter, std::tuple_cat(std::make_tuple(x), arg)); \ } } // Building