|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r79705 - sandbox/type_erasure/libs/type_erasure/example
From: steven_at_[hidden]
Date: 2012-07-23 15:57:24
Author: steven_watanabe
Date: 2012-07-23 15:57:24 EDT (Mon, 23 Jul 2012)
New Revision: 79705
URL: http://svn.boost.org/trac/boost/changeset/79705
Log:
Try to explain better how multi type concepts work.
Text files modified:
sandbox/type_erasure/libs/type_erasure/example/multi.cpp | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
Modified: sandbox/type_erasure/libs/type_erasure/example/multi.cpp
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/example/multi.cpp (original)
+++ sandbox/type_erasure/libs/type_erasure/example/multi.cpp 2012-07-23 15:57:24 EDT (Mon, 23 Jul 2012)
@@ -51,9 +51,7 @@
__addable`<>` requires the types of the arguments to be
the same. We can also capture relationships among several types.
To do this we'll need to identify each type with a
- __placeholder. Also, we can no longer capture the
- variables independently, since they are connected,
- so we use __tuple to capture them all at once.
+ __placeholder.
*/
int array[5];
@@ -64,15 +62,36 @@
addable<_a, _b, _a>
> requirements;
- tuple<requirements, _a, _b> t(&array[0], 2);
- any<requirements, _a> x(get<0>(t) + get<1>(t));
+ /*`
+ Also, we can no longer capture the variables
+ independently.
+ ``
+ any<requirements, _a> ptr(&array[0]); // illegal
+ ``
+ This doesn't work because the library needs
+ to know the type that _b binds to when it
+ captures the concept bindings. We need to
+ specify the bindings of both placeholders
+ when we construct the __any.
+ */
+
+ typedef mpl::map<mpl::pair<_a, int*>, mpl::pair<_b, int> > types;
+ any<requirements, _a> ptr(&array[0], static_binding<types>());
+ any<requirements, _b> idx(2, static_binding<types>());
+ any<requirements, _a> x(ptr + idx);
// x now holds array + 2
+
/*`
Here the arguments of `+` are no longer the same.
What we require is that the dynamic bindings of
the two arguments to `+` must map the placeholders
`_a` and `_b` to the same types.
+
+ We can also use __tuple to avoid having to
+ write out the map out explicitly.
*/
+ tuple<requirements, _a, _b> t(&array[0], 2);
+ any<requirements, _a> y(get<0>(t) + get<1>(t));
//]
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk