Front Page / Metafunctions / Miscellaneous / inherit_linearly |
template< typename Types , typename Node , typename Root = empty_base > struct inherit_linearly : fold<Types,Root,Node> { };
A convenience wrapper for fold to use in the context of sequence-driven class composition. Returns the result the successive application of binary Node to the result of the previous Node invocation (Root if it's the first call) and every type in the Forward Sequence Types in order.
#include <boost/mpl/inherit_linearly.hpp>
Parameter | Requirement | Description |
---|---|---|
Types | Forward Sequence | Types to inherit from. |
Node | Binary Lambda Expression | A derivation metafunction. |
Root | A class type | A type to be placed at the root of the class hierarchy. |
For any Forward Sequence types, binary Lambda Expression node, and arbitrary class type root:
typedef inherit_linearly<types,node,root>::type r;
Return type: | A class type. |
---|---|
Semantics: | Equivalent to typedef fold<types,root,node>::type r; |
Linear. Exactly size<types>::value applications of node.
template< typename T > struct tuple_field { T field; }; template< typename T > inline T& field(tuple_field<T>& t) { return t.field; } typedef inherit_linearly< vector<int,char const*,bool> , inherit< _1, tuple_field<_2> > >::type tuple; int main() { tuple t; field<int>(t) = -1; field<char const*>(t) = "text"; field<bool>(t) = false; std::cout << field<int>(t) << 'n' << field<char const*>(t) << 'n' << field<bool>(t) << 'n' ; }