Structure (very complicated) struct complicated_struct { int i; short s; double d; unsigned u; };
2 / 71
Something that must not work... #include #include "magic_get.hpp"
struct complicated_struct { /* … */ };
int main() { using namespace pod_ops;
complicated_struct s {1, 2, 3.0, 4}; std::cout << "s == " << s << std::endl; }
// Compile time error? 3 / 71
But how?..
antoshkka@home:~$ ./test
s ==
{1, 2, 3.0, 4}
4 / 71
What's in the header? #include #include "magic_get.hpp"
struct complicated_struct { /* … */ };
int main() { using namespace pod_ops;
complicated_struct s {1, 2, 3.0, 4}; std::cout << "s == " << s << std::endl; }
// Compile time error? 5 / 71
We need to go deeper... template std::basic_ostream& operator<<(std::basic_ostream& out, const T& value) { flat_write(out, value); return out; }
6 / 71
... template void flat_write(std::basic_ostream& out, const T& val) { out << '{'; detail::flat_print_impl<0, flat_tuple_size::value >::print(out, val); out << '}'; }
7 / 71
O_O template struct flat_print_impl {
template static void print (Stream& out, const T& value) { if (!!FieldIndex) out << ", "; out << flat_get(value);
// std::get(value)
flat_print_impl::print(out, value); }
};
8 / 71
Wow!.. /// Returns const reference to a field with index `I` /// Example usage: flat_get<0>(my_structure()); template decltype(auto) flat_get(const T& val) noexcept;
/// `flat_tuple_size` has a member `value` that constins fields count /// Example usage: std::array::value > a; template using flat_tuple_size; 9 / 71
How to count fields?
Idea for counting fields static_assert(std::is_pod::value, "")
11 / 71
Idea for counting fields static_assert(std::is_pod::value, "")
T { args... }
12 / 71
Idea for counting fields static_assert(std::is_pod::value, "")
T { args... }
sizeof...(args) <= fields count
typeid(args)... == typeid(fields)...
13 / 71
Idea for counting fields static_assert(std::is_pod::value, "")
T { args... }
sizeof...(args) <= fields count
typeid(args)... == typeid(fields)...
14 / 71
Idea for counting fields static_assert(std::is_pod::value, "")
T { args... }
sizeof...(args) <= fields count
typeid(args)... == typeid(fields)...
sizeof(char) == 1 sizeof...(args) <= sizeof(T)
15 / 71
Idea for counting fields static_assert(std::is_pod::value, "")
Putting together Idea #2 BOOST_MAGIC_GET_REGISTER_TYPE(unsigned char
, 1)
BOOST_MAGIC_GET_REGISTER_TYPE(unsigned short
, 2)
BOOST_MAGIC_GET_REGISTER_TYPE(unsigned int
, 3)
BOOST_MAGIC_GET_REGISTER_TYPE(unsigned long
, 4)
BOOST_MAGIC_GET_REGISTER_TYPE(unsigned long long
, 5)
BOOST_MAGIC_GET_REGISTER_TYPE(signed char
, 6)
BOOST_MAGIC_GET_REGISTER_TYPE(short
, 7)
BOOST_MAGIC_GET_REGISTER_TYPE(int
, 8)
BOOST_MAGIC_GET_REGISTER_TYPE(long
, 9)
BOOST_MAGIC_GET_REGISTER_TYPE(long long
, 10) 32 / 71
Putting together Idea #2 template constexpr auto type_to_array_of_type_ids(std::size_t* types) noexcept -> decltype(T{ ubiq_constructor{}... }) { T tmp{ ubiq_val< I >{types}... }; return tmp; }
33 / 71
Putting together Idea #2 template constexpr auto as_tuple_impl(std::index_sequence) noexcept { constexpr auto a = array_of_type_ids();
P376: Stop leaks if safe to do so. See section 6 for proper. clean up. STORAGE STATEMENTS: P403: Keep Cool Store in a well-ventilated place. Page 2 of 11 ...
Sign in. Page. 1. /. 6. Loading⦠Page 1 of 6. Page 1 of 6. Page 2 of 6. Page 2 of 6. Page 3 of 6. Page 3 of 6. 2016-17 ENG App pkt.pdf. 2016-17 ENG App pkt.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying 2016-17 ENG App pkt.pdf. Page