FTXUI/include/ftxui/dom/take_any_args.hpp

49 lines
1.3 KiB
C++
Raw Permalink Normal View History

2023-08-19 19:56:36 +08:00
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
2022-03-31 08:17:43 +08:00
#ifndef FTXUI_DOM_TAKE_ANY_ARGS_HPP
#define FTXUI_DOM_TAKE_ANY_ARGS_HPP
2021-05-02 02:40:35 +08:00
// IWYU pragma: private, include "ftxui/dom/elements.hpp"
#include <ftxui/dom/node.hpp>
2019-01-06 23:14:19 +08:00
2021-07-10 20:23:46 +08:00
namespace ftxui {
template <class T>
2022-03-31 08:17:43 +08:00
void Merge(Elements& /*container*/, T /*element*/) {}
template <>
inline void Merge(Elements& container, Element element) {
container.push_back(std::move(element));
}
template <>
inline void Merge(Elements& container, Elements elements) {
for (auto& element : elements) {
container.push_back(std::move(element));
}
}
2019-01-06 23:14:19 +08:00
// Turn a set of arguments into a vector.
template <class... Args>
2019-01-13 01:24:46 +08:00
Elements unpack(Args... args) {
std::vector<Element> vec;
(Merge(vec, std::move(args)), ...);
2019-01-06 23:14:19 +08:00
return vec;
}
// Make |container| able to take any number of argments.
#define TAKE_ANY_ARGS(container) \
template <class... Args> \
Element container(Args... children) { \
return container(unpack(std::forward<Args>(children)...)); \
}
2021-07-10 20:23:46 +08:00
TAKE_ANY_ARGS(vbox)
TAKE_ANY_ARGS(hbox)
TAKE_ANY_ARGS(dbox)
TAKE_ANY_ARGS(hflow)
} // namespace ftxui
2022-03-31 08:17:43 +08:00
#endif // FTXUI_DOM_TAKE_ANY_ARGS_HPP