32namespace triqs::utility {
37 template <
typename T>
struct factories {
38 template <
typename U>
static T invoke(U &&x) {
return T(std::forward<U>(x)); }
42 template <
typename T>
struct factories<std::vector<T>> {
43 using R = std::vector<T>;
46 static R invoke(R &&x) {
return R(std::move(x)); }
47 static R invoke(R
const &x) {
return R(x); }
48 static R invoke(R &x) {
return R(x); }
51 template <
typename U>
static R invoke(std::vector<U> &&v) {
52 auto tmp = std::move(v);
54 r.reserve(tmp.size());
55 for (
auto &x : tmp) r.push_back(factories<T>::invoke(std::move(x)));
59 template <
typename U>
static R invoke(std::vector<U> &v) {
62 for (
auto &x : v) r.push_back(factories<T>::invoke(x));
66 template <
typename U>
static R invoke(std::vector<U>
const &v) {
69 for (
auto &x : v) r.push_back(factories<T>::invoke(x));
95 template <
typename T,
typename... U> T
factory(U &&...x) {
return detail::factories<T>::invoke(std::forward<U>(x)...); }
T factory(U &&...x)
Generic factory to construct an object of a given type from an arbitrary parameter pack of arguments.
Common macros used in TRIQS.