Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- template< typename aggregate >
- struct embrace
- : aggregate
- {
- template< typename ...arguments, bool is_noexcept = noexcept(aggregate{std::declval< arguments >()...}) >
- embrace(arguments &&... _arguments) noexcept(is_noexcept)
- : aggregate{std::forward< arguments >(_arguments)...}
- { ; }
- };
- // main.cpp
- #include <type_traits>
- #include <cstdlib>
- #include <cassert>
- int
- main()
- {
- struct A {};
- struct B {};
- {
- struct S { A a; B b; }; // aggregate
- using E = embrace< S >;
- E e(A{}, B{}); // "parentheses"-constructible => can be used as usual types
- e.a = {}; e.b = {}; // accessible
- static_assert(std::is_constructible< E, A, B >{});
- static_assert(std::is_constructible< E, A >{}); // "missed field initializers" warning desired anywere
- static_assert(!std::is_constructible< E, struct C >{}); // don't want hard error here
- }
- {
- struct S
- {
- A a;
- B f() { return {}; }
- B b = f();
- };
- using E = embrace< S >;
- E e(A{}, B{}); // "parentheses"-constructible => can be used as usual types
- e.a = {}; e.b = {}; // accessible
- static_assert(std::is_constructible< E, A, B >{});
- static_assert(std::is_constructible< E, A >{});
- static_assert(!std::is_constructible< E, struct C >{}); // don't want hard error here
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement