From efe421e98262e929fa3f19d5079ebebc228ddb93 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 9 Jun 2016 23:10:35 +0300 Subject: [PATCH] Link to the docs provided --- README.md | 132 ++---------------------------------------------------- 1 file changed, 3 insertions(+), 129 deletions(-) diff --git a/README.md b/README.md index 3d09f02..176e5be 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ This C++14 library is meant for accessing structure elements by index and providing other std::tuple like methods for user defined POD types. +[Latest documentation](http://apolukhin.github.com/magic_get/index.html) + + ### Motivating example ```c++ #include @@ -27,136 +30,7 @@ Outputs: my_struct has 3 fields: { 100, H, 3.14159 } ``` -### Flattening -All the methods with prefix `flat_` represent a template parameter type as flat structure without static members: -```c++ -// Helper structure. -struct my_struct_nested { short a1; int a2; }; - -// This structure: -struct my_struct { - int a0; - static const cvalue = 1000; - my_struct_nested nested; - short a3_a4[2]; -}; - -// will be flattened and represented as: -struct my_struct_flat { - int a0; - short a1; - int a2 - short a3; - short a4 -}; -``` -So that -* `flat_get<2>(my_struct{})` will return `my_struct::my_struct_nested::a2` field -* `flat_get<3>(my_struct{})` will return `my_struct::a3_a4[0]` field - -Same story with arrays: -```c++ - int i[2][2] = {{10, 11}, {12, 13} }; - assert(flat_get<1>(i) == 11); -``` - -### API -```c++ -/// Returns const reference to a field with index `I` in flattened `T`. -/// Example usage: flat_get<0>(my_structure()); -template -decltype(auto) flat_get(const T& val) noexcept; - - -/// Returns reference to a field with index `I` in flattened `T`. -/// Requires: `T` must not have const fields. -/// Example usage: flat_get<0>(my_structure()); -template -decltype(auto) flat_get(T& val, typename std::enable_if< std::is_trivially_assignable::value>::type* = 0); - - -/// `flat_tuple_element` has a `typedef type-of-a-field-with-index-I-in-flattened-T type;` -/// Example usage: std::vector< flat_tuple_element<0, my_structure>::type > v; -template -using flat_tuple_element; - - -/// Type of a field with index `I` in flattened `T` -/// Example usage: std::vector< flat_tuple_element_t<0, my_structure> > v; -template -using flat_tuple_element_t = typename flat_tuple_element::type; - - -/// `flat_tuple_size` has a member `value` that constins fields count in a flattened `T`. -/// Example usage: std::array::value > a; -template -using flat_tuple_size; - - -/// `flat_tuple_size_v` is a template variable that constins fields count in a flattened `T`. -/// Example usage: std::array > a; -template -constexpr std::size_t flat_tuple_size_v = flat_tuple_size::value; - - -/// Creates an `std::tuple` from a flattened T. -/// Example usage: -/// struct my_struct { int i, short s; }; -/// my_struct s {10, 11}; -/// std::tuple t = flat_to_tuple(s); -/// assert(get<0>(t) == 10); -template -auto flat_make_tuple(const T& val) noexcept; - - -/// Creates an `std::tuple` with lvalue references to fields of a flattened T. -/// Example usage: -/// struct my_struct { int i, short s; }; -/// my_struct s; -/// flat_tie(s) = std::tuple{10, 11}; -/// assert(s.s == 11); -template -auto flat_tie(T& val, typename std::enable_if< std::is_trivially_assignable::value>::type* = 0 ) noexcept; - - -/// Writes to `out` POD `value` -/// Example usage: -/// struct my_struct { int i, short s; }; -/// my_struct s{12, 13}; -/// flat_write(std::cout, s); // outputs '{12, 13}' -template -void flat_write(std::basic_ostream& out, const T& value); - - -/// Reads POD `value` from stream `in` -/// Example usage: -/// struct my_struct { int i, short s; }; -/// my_struct s; -/// std::stringstream ss; -/// ss << "{12, 13}"; -/// ss >> s; -/// assert(s.i == 12); -/// assert(s.i == 13); -template -void flat_read(std::basic_istream& in, T& value); - - -/// Contains comparison operators and stream operators for any POD types that does not have it's own operators. -/// If POD is comparable or streamable using it's own operator or it's conversion operator, then the original operator is be used. -/// -/// Example usage: -/// struct comparable_struct { // No operators defined for that structure -/// int i; short s; char data[7]; bool bl; int a,b,c,d,e,f; -/// }; -/// using namespace pod_ops; -/// -/// comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11}; -/// comparable_struct s2 {0, 1, "Hello", false, 6,7,8,9,10,11111}; -/// assert(s1 < s2); -/// std::cout << s1 << std::endl; // Outputs: {0, 1, H, e, l, l, o, , , 0, 6, 7, 8, 9, 10, 11} -namespace pod_ops; -``` ### Requirements and Limitations