Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template<class S>
- S make_struct() {
- S s = {};
- return s;
- }
- template<class S, class T1>
- S make_struct(T1 t1) {
- S s = { t1 };
- return s;
- }
- template<class S, class T1, class T2>
- S make_struct(T1 t1, T2 t2) {
- S s = { t1, t2 };
- return s;
- }
- // ... etc.
- struct X { int a, b; };
- int main() {
- X x = make_struct<X>(1, 2);
- std::cout << x.a << ", " << x.b << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement