[TypeErasure] Forward constructors and binded types

Hi,, In the example from the doc typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct; std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t)); I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me? Best, Vicente

On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
I'd guess that a std::vector<double>&, more specifically the vec is stored as the _a& in the tuple<construct, _&a, _b, _c>. Hmm... Now I'm not sure anymore. Maybe it's a new std::vector<double> that's stored and the std::vector<double> CTOR args are 10 and double. IOW the equivalent of: std::vector<double> v_a(10,2.5) is stored in v? Could the documentation on this be clarified a bit? TIA. -regards, Larry

AMDG On 07/18/2012 06:57 AM, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
I'd guess that a std::vector<double>&, more specifically the vec is stored as the _a& in the tuple<construct, _&a, _b, _c>. Hmm... Now I'm not sure anymore. Maybe it's a new std::vector<double> that's stored and the std::vector<double> CTOR args are 10 and double. IOW the equivalent of:
std::vector<double> v_a(10,2.5)
is stored in v?
Yes.
Could the documentation on this be clarified a bit?
What needs to be clarified? This is the only reasonable behavior: The arguments obviously match constructible<_a(const _b&, const _c&)> right? Therefore this constructor is the one called. _a was bound to std::vector<double>, so this is the type created. In Christ, Steven Watanabe

Steven Watanabe-4 wrote
AMDG
On 07/18/2012 06:57 AM, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
I'd guess that a std::vector<double>&, more specifically the vec is stored as the _a& in the tuple<construct, _&a, _b, _c>. Hmm... Now I'm not sure anymore. Maybe it's a new std::vector<double> that's stored and the std::vector<double> CTOR args are 10 and double. IOW the equivalent of:
std::vector<double> v_a(10,2.5)
is stored in v?
Yes.
Could the documentation on this be clarified a bit?
What needs to be clarified? This is the only reasonable behavior: The arguments obviously match constructible<_a(const _b&, const _c&)> right? Therefore this constructor is the one called. _a was bound to std::vector<double>, so this is the type created.
In Christ, Steven Watanabe
My question is how the bind of _a to std::vector<double> if the t variable is not passed in the constructor of any? I'm sure I'm missing something evident. Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/TypeErasure-Forward-constructors-and-bind... Sent from the Boost - Dev mailing list archive at Nabble.com.

Vicente Botet wrote
Steven Watanabe-4 wrote
AMDG
On 07/18/2012 06:57 AM, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
I'd guess that a std::vector<double>&, more specifically the vec is stored as the _a& in the tuple<construct, _&a, _b, _c>. Hmm... Now I'm not sure anymore. Maybe it's a new std::vector<double> that's stored and the std::vector<double> CTOR args are 10 and double. IOW the equivalent of:
std::vector<double> v_a(10,2.5)
is stored in v?
Yes.
Could the documentation on this be clarified a bit?
What needs to be clarified? This is the only reasonable behavior: The arguments obviously match constructible<_a(const _b&, const _c&)> right? Therefore this constructor is the one called. _a was bound to std::vector<double>, so this is the type created.
In Christ, Steven Watanabe
My question is how the bind of _a to std::vector<double> if the t variable is not passed in the constructor of any? I'm sure I'm missing something evident.
Sorry I wanted to say, how the bind of _a to std::vector<double> *is know by v* if the t variable is not passed in the constructor of any? Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/TypeErasure-Forward-constructors-and-bind... Sent from the Boost - Dev mailing list archive at Nabble.com.

AMDG On 07/18/2012 09:54 AM, Vicente Botet wrote:
Vicente Botet wrote
Steven Watanabe-4 wrote
AMDG
On 07/18/2012 06:57 AM, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
<snip>
Sorry I wanted to say, how the bind of _a to std::vector<double> *is know by v* if the t variable is not passed in the constructor of any?
Each any<> stores a complete vtable. i.e. any<construct, _b> knows what _a, _b, and _c all bind to. In Christ, Steven Watanabe

Steven Watanabe-4 wrote
AMDG
On 07/18/2012 09:54 AM, Vicente Botet wrote:
Vicente Botet wrote
Steven Watanabe-4 wrote
AMDG
On 07/18/2012 06:57 AM, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
<snip>
Sorry I wanted to say, how the bind of _a to std::vector<double> *is know by v* if the t variable is not passed in the constructor of any?
Each any<> stores a complete vtable. i.e. any<construct, _b> knows what _a, _b, and _c all bind to.
Please, could you point me to the any constructor used in any<construct, _a> v(get<1>(t), get<2>(t)); Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/TypeErasure-Forward-constructors-and-bind... Sent from the Boost - Dev mailing list archive at Nabble.com.

AMDG On 07/18/2012 10:27 AM, Vicente Botet wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote: > <snip> > > std::vector<double> vec; > int i = 10; > double d = 2.5; > tuple<construct, _a&, _b, _c> t(vec, i, d); > any<construct, _a> v(get<1>(t), get<2>(t)); >
<snip>
Please, could you point me to the any constructor used in
any<construct, _a> v(get<1>(t), get<2>(t));
Do you mean: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... In Christ, Steven Watanabe

Steven Watanabe-4 wrote
AMDG
On 07/18/2012 10:27 AM, Vicente Botet wrote:
> On 07/18/12 01:29, Vicente J. Botet Escriba wrote: >> <snip> >> >> std::vector<double> vec; >> int i = 10; >> double d = 2.5; >> tuple<construct, _a&, _b, _c> t(vec, i, d); >> any<construct, _a> v(get<1>(t), get<2>(t)); >>
<snip>
Please, could you point me to the any constructor used in
any<construct, _a> v(get<1>(t), get<2>(t));
Do you mean:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
Yes, i guess. Is the following correct? class X { public: X(int, double); }; std::vector<double> vec; int i = 10; double d = 2.5; X x; tuple<construct, _a&, _b, _c> t1(vec, i, d); tuple<construct, _a&, _b, _c> t2(x, i, d); any<construct, _a> v1(get<1>(t1), get<2>(t1)); any<construct, _a> v2(get<1>(t2), get<2>(t2)); If yes, how v1 is bound to vec and v2 to x? Vicente Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/TypeErasure-Forward-constructors-and-bind... Sent from the Boost - Dev mailing list archive at Nabble.com.

AMDG On 07/18/2012 10:47 AM, Vicente Botet wrote:
Is the following correct?
class X { public: X(int, double); };
std::vector<double> vec; int i = 10; double d = 2.5; X x;
tuple<construct, _a&, _b, _c> t1(vec, i, d); tuple<construct, _a&, _b, _c> t2(x, i, d); any<construct, _a> v1(get<1>(t1), get<2>(t1)); any<construct, _a> v2(get<1>(t2), get<2>(t2));
If yes, how v1 is bound to vec and v2 to x?
It isn't. v1 stores a std::vector<double> which is constructed in place and is not related to vec in any way. v2 again hold a separate object of type X, which is created using X(int, double). In Christ, Steven Watanabe

Steven Watanabe-4 wrote
AMDG
On 07/18/2012 10:47 AM, Vicente Botet wrote:
Is the following correct?
class X { public: X(int, double); };
std::vector<double> vec; int i = 10; double d = 2.5; X x;
tuple<construct, _a&, _b, _c> t1(vec, i, d); tuple<construct, _a&, _b, _c> t2(x, i, d); any<construct, _a> v1(get<1>(t1), get<2>(t1)); any<construct, _a> v2(get<1>(t2), get<2>(t2));
If yes, how v1 is bound to vec and v2 to x?
It isn't. v1 stores a std::vector<double> which is constructed in place and is not related to vec in any way.
v2 again hold a separate object of type X, which is created using X(int, double).
Well, I think I have understood how this can work. get<1>(t1) returns an any that has a binding std::vector<double>,int,double and is this binding that allows to associate _a to std::vector<double>. I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used. Best, Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/TypeErasure-Forward-constructors-and-bind... Sent from the Boost - Dev mailing list archive at Nabble.com.

On 07/18/12 13:43, Vicente Botet wrote:
Steven Watanabe-4 wrote
AMDG
On 07/18/2012 10:47 AM, Vicente Botet wrote:
Is the following correct?
class X { public: X(int, double); };
std::vector<double> vec; int i = 10; double d = 2.5; X x;
tuple<construct, _a&, _b, _c> t1(vec, i, d); tuple<construct, _a&, _b, _c> t2(x, i, d); any<construct, _a> v1(get<1>(t1), get<2>(t1)); any<construct, _a> v2(get<1>(t2), get<2>(t2));
If yes, how v1 is bound to vec and v2 to x?
It isn't. v1 stores a std::vector<double> which is constructed in place and is not related to vec in any way.
v2 again hold a separate object of type X, which is created using X(int, double).
Well, I think I have understood how this can work.
get<1>(t1) returns an any that has a binding std::vector<double>,int,double and is this binding that allows to associate _a to std::vector<double>.
I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used.
+1 Before Vicente mentioned the binding thing, I thought: get<1>(t1) would return an any which was bound to an int, and: get<2>(t1) would return an any which was bound to a double, but now, if Vicente is correct, the get's return an any that has the complete construct bindings. Thanks Vicente. -regards, Larry

Larry Evans-3 wrote
On 07/18/12 13:43, Vicente Botet wrote:
I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used.
+1
Before Vicente mentioned the binding thing, I thought:
get<1>(t1)
would return an any which was bound to an int, and:
get<2>(t1)
would return an any which was bound to a double, but now, if Vicente is correct, the get's return an any that has the complete construct bindings.
The behaviour of get can probably be deduced from its signature: namespace boost { namespace type_erasure { template<typename Concept, class... T> class tuple; template<int N, typename Concept, class... T> any< Concept, TN > & get(tuple< Concept, T...> & arg); template<int N, typename Concept, class... T> const any< Concept, TN > & get(const tuple< Concept, T...> & arg); } } http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... However, get is not actually documented in the Reference section (a part from the signature above) and it is not linked in the rest of the documentation. get should be documented in the Reference section and a few lines in the documentation body (get is first used in the Function with Multiple Arguments section) should explain how get works. Thanks, --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/TypeErasure-Forward-constructors-and-bind... Sent from the Boost - Dev mailing list archive at Nabble.com.

On 07/18/12 15:08, Larry Evans wrote:
On 07/18/12 13:43, Vicente Botet wrote:
Steven Watanabe-4 wrote
AMDG
On 07/18/2012 10:47 AM, Vicente Botet wrote:
Is the following correct?
class X { public: X(int, double); };
std::vector<double> vec; int i = 10; double d = 2.5; X x;
tuple<construct, _a&, _b, _c> t1(vec, i, d); tuple<construct, _a&, _b, _c> t2(x, i, d); any<construct, _a> v1(get<1>(t1), get<2>(t1)); any<construct, _a> v2(get<1>(t2), get<2>(t2));
If yes, how v1 is bound to vec and v2 to x?
It isn't. v1 stores a std::vector<double> which is constructed in place and is not related to vec in any way.
v2 again hold a separate object of type X, which is created using X(int, double).
Well, I think I have understood how this can work.
get<1>(t1) returns an any that has a binding std::vector<double>,int,double and is this binding that allows to associate _a to std::vector<double>.
I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used.
+1
Before Vicente mentioned the binding thing, I thought:
get<1>(t1)
would return an any which was bound to an int, and:
get<2>(t1)
would return an any which was bound to a double, but now, if Vicente is correct, the get's return an any that has the complete construct bindings.
Thanks Vicente.
The construction2 function here: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... was most helpful to me. The attached shows that 2 different bindings can be used to create 2 arguments to a construction of the 3ird placeholder, and it still works. I would have thought that the same bindings would have been required for the placeholders. The attached produces output of: St5dequeIdSaIdEE suggesting the type constructed comes from the 1st placeholder. When the code is changed to: any<construct, _b> size(10, bindings1); any<construct, _c> val(2.5, bindings2); the output is: St6vectorIdSaIdEE supporting the above conclusion. Do the docs say anywhere that this is what happens when 2 different bindings are used to construct something? -regards, Larry

AMDG On 07/19/2012 07:36 AM, Larry Evans wrote:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
was most helpful to me. The attached shows that 2 different bindings can be used to create 2 arguments to a construction of the 3ird placeholder, and it still works. I would have thought that the same bindings would have been required for the placeholders.
They are. This happens to work because I cheated a little in the assertions, but it's really undefined behavior.
The attached produces output of:
St5dequeIdSaIdEE
suggesting the type constructed comes from the 1st placeholder. When the code is changed to:
any<construct, _b> size(10, bindings1); any<construct, _c> val(2.5, bindings2);
the output is:
St6vectorIdSaIdEE
supporting the above conclusion.
Do the docs say anywhere that this is what happens when 2 different bindings are used to construct something?
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... "The bindings of all the arguments that are any's, must be the same." In Christ, Steven Watanabe

AMDG On 07/18/2012 11:43 AM, Vicente Botet wrote:
Well, I think I have understood how this can work.
get<1>(t1) returns an any that has a binding std::vector<double>,int,double and is this binding that allows to associate _a to std::vector<double>.
Exactly.
I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used.
You mean like: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... and http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... As for how it's used, a number of functions take an optional binding argument such as http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... In Christ, Steven Watanabe

Le 19/07/12 21:17, Steven Watanabe a écrit :
AMDG
On 07/18/2012 11:43 AM, Vicente Botet wrote:
Well, I think I have understood how this can work.
get<1>(t1) returns an any that has a binding std::vector<double>,int,double and is this binding that allows to associate _a to std::vector<double>.
Exactly.
I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used.
You mean like:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
and
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
As for how it's used, a number of functions take an optional binding argument such as http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
No, this is good, but it is reference documentation. I was thinking more as part of the tutorial, what is the concept behind, why it is needed, ... IMO the current tutorial hides this major concept of the library. Vicente

On 7/19/2012 1:41 PM, Vicente J. Botet Escriba wrote:
Le 19/07/12 21:17, Steven Watanabe a écrit :
AMDG
On 07/18/2012 11:43 AM, Vicente Botet wrote:
Well, I think I have understood how this can work.
get<1>(t1) returns an any that has a binding std::vector<double>,int,double and is this binding that allows to associate _a to std::vector<double>.
Exactly.
I 'd appreciate if the documentation clarifies what these bindings are, how they are built built and used.
You mean like:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
and
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
As for how it's used, a number of functions take an optional binding argument such as http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
No, this is good, but it is reference documentation. I was thinking more as part of the tutorial, what is the concept behind, why it is needed, ... IMO the current tutorial hides this major concept of the library.
+1. For the record, I got hung up in the tutorial in exactly the same place as the OP. Had there been a more extensive description of tuple, why it's needed, and a who-knows-what-and-when about the different objects in play -- including the any's returned by get -- it would have been much easier. I'd also like to second the call for reference docs on the get function. -- Eric Niebler BoostPro Computing http://www.boostpro.com

AMDG On 07/23/2012 10:56 AM, Eric Niebler wrote:
+1. For the record, I got hung up in the tutorial in exactly the same place as the OP. Had there been a more extensive description of tuple, why it's needed, and a who-knows-what-and-when about the different objects in play -- including the any's returned by get -- it would have been much easier.
I've changed the example to show how to do this without tuple first. The key to understanding this is that tuple<requirements, _a, _b> is just shorthand for creating the anys with an mpl::map<mpl::pair<_a, int*>, mpl::pair<_b, int> > In Christ, Steven Watanabe

On 07/23/12 15:05, Steven Watanabe wrote:
AMDG
On 07/23/2012 10:56 AM, Eric Niebler wrote:
+1. For the record, I got hung up in the tutorial in exactly the same place as the OP. Had there been a more extensive description of tuple, why it's needed, and a who-knows-what-and-when about the different objects in play -- including the any's returned by get -- it would have been much easier.
I've changed the example to show how to do this without tuple first. The key to understanding this is that tuple<requirements, _a, _b> is just shorthand for creating the anys with an mpl::map<mpl::pair<_a, int*>, mpl::pair<_b, int> >
Another example of demonstrating that the tuple is shorthand is attached to: http://article.gmane.org/gmane.comp.lib.boost.devel/232953 HTH. -Larry

On 7/18/12 5:44 PM, Steven Watanabe wrote:
On 07/18/2012 06:57 AM, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
I don't see which type is constructed and stored in v and how this type is given. That is I don't see how _a is binded. Could you help me?
I'd guess that a std::vector<double>&, more specifically the vec is stored as the _a& in the tuple<construct, _&a, _b, _c>. Hmm... Now I'm not sure anymore. Maybe it's a new std::vector<double> that's stored and the std::vector<double> CTOR args are 10 and double. IOW the equivalent of:
std::vector<double> v_a(10,2.5)
is stored in v?
Yes.
Could the documentation on this be clarified a bit?
What needs to be clarified? This is the only reasonable behavior:
Just spelling out some thoughts I had while reading the docu: Even though, it would help to have this information in the docu. The way it is written now feels a bit like playing Jeopardy, you present solutions and the reader tries to figure out the problem. additionally I do not quite gasp on what I could use this feature for. the above is much more complex as using any<...> v = std::vector<double>(10, 2.5); what am I buying with it? And couldn't another syntax like any<...> v(binding_of(vec), (int)10, (double)2.5); be made to work, and be much more comfortable? regards Fabio

AMDG On 07/18/2012 01:32 PM, Fabio Fracassi wrote:
Just spelling out some thoughts I had while reading the docu:
Even though, it would help to have this information in the docu. The way it is written now feels a bit like playing Jeopardy, you present solutions and the reader tries to figure out the problem.
additionally I do not quite gasp on what I could use this feature for. the above is much more complex as using any<...> v = std::vector<double>(10, 2.5); what am I buying with it?
The point is to allow constructors to be captured just like any other function. When the constructor is called, you don't have to know the contained types. Also, this feature has one very obvious use: the copy constructor. If we need the ability to copy an any<Concept, _a>, then Concept needs to include constructible<_a(const _a&)>.
And couldn't another syntax like any<...> v(binding_of(vec), (int)10, (double)2.5); be made to work, and be much more comfortable?
- binding_of takes an any as an argument. vec is a std::vector. - This syntax does, in fact, work if the Concept includes construcible<_a(int, double)> and if we replace vec with an any. In Christ, Steven Watanabe

Fabio Fracassi wrote:
Just spelling out some thoughts I had while reading the docu:
Even though, it would help to have this information in the docu. The way it is written now feels a bit like playing Jeopardy, you present solutions and the reader tries to figure out the problem.
I would like to add to this: I got the impression that TypeErasure is something really great to have - if and only if you really understand the problem it solves and how to solve it. Here I am in the same situation as with proto: I will read the docs again and again and not really get sure about whether I am doing it right. This is not the first boost library that misses a great tutorial. I think we have a dilemma here: The C++ skill level of the library authors is (and has to be) so extraordinary that they fully understand the implementation of mpl or proto and that they simply do not understand that mediocre programmers as me (sorry for "only" 15 years of C++ experience) stumble over questions on a much lower level. I enjoyed this and other threads and some comments in the docs that simply tell me I am an absolute beginner. For me reference docs are helpful when I am through the normal docs, not as a first contact. Please note that I hesitate to blame Steven for the fact that the docs do not meet my needs. I expect TypeErasure to be a great library with a near- perfect and well-thought implementation, only the missing step-by-step intro is exactly my problem with this library. I can imagine that writing it should not be Steven's burden. Like for the STL which was not written by Scott Meyers, but only perfectly explained. @Steven: If you have some more examples at hand, please insert them into the examples section. If you have some silly little example of the problem the library solves, please put it into the introduction chapter. People might read the library description and not get a clue what it was meant for. Markus

On 07/22/12 10:18, Markus Werle wrote:
Fabio Fracassi wrote:
Just spelling out some thoughts I had while reading the docu:
Even though, it would help to have this information in the docu. The way it is written now feels a bit like playing Jeopardy, you present solutions and the reader tries to figure out the problem.
I would like to add to this: I got the impression that TypeErasure is something really great to have - if and only if you really understand the problem it solves and how to solve it.
I've been trying to see the relation between type_erasure and some design patterns. This link: http://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html suggests a relationship between type erasure and the bridge pattern. Since the bridge pattern is documented and the bridge pattern docs show the type of problem it solves, maybe Steven could explain the difference between the problem his type_erasure library solves and the problem solved by the bridge pattern, and *maybe* that would be some help. AFAICT, the type_erasure library is also like the object adapter pattern in that it contains a pointer to the adaptee in the any::data member variable. However, unlike the adapter, there's no virtual functions which the adaptee implements. The type_erasure library is also like the bridge pattern in that it hides the implementation of the abstraction. AFAICT, the abstraction (using the bridge pattern term), in the type_erasure library, is the any::table member. Stephen, is that comparison anywhere close? -regards, Larry

AMDG On 07/22/2012 08:18 AM, Markus Werle wrote:
Fabio Fracassi wrote:
Just spelling out some thoughts I had while reading the docu:
Even though, it would help to have this information in the docu. The way it is written now feels a bit like playing Jeopardy, you present solutions and the reader tries to figure out the problem.
I would like to add to this: I got the impression that TypeErasure is something really great to have - if and only if you really understand the problem it solves and how to solve it.
As far as the problem the library solves goes, TypeErasure is a generalization of several existing components: Boost.Any: any<mpl::vector<copy_constructible<>, typeid_<> > > Boost.Function: any<mpl::vector<copy_constructible<>, typeid_<>, callable<void(int)> > > AnyIterator: any<mpl::vector<forward_iterator<>, same_type<forward_iterator<>::value_type, int> > > I expect that the majority of uses of the library will be about this level of complexity. In Christ, Steven Watanabe

On Sun, Jul 22, 2012 at 11:18 AM, Markus Werle <numerical.simulation@web.de> wrote:
Fabio Fracassi wrote:
Just spelling out some thoughts I had while reading the docu:
Even though, it would help to have this information in the docu. The way it is written now feels a bit like playing Jeopardy, you present solutions and the reader tries to figure out the problem.
I would like to add to this: I got the impression that TypeErasure is something really great to have - if and only if you really understand the problem it solves and how to solve it.
Here I am in the same situation as with proto: I will read the docs again and again and not really get sure about whether I am doing it right.
This is not the first boost library that misses a great tutorial. I think we have a dilemma here: The C++ skill level of the library authors is (and has to be) so extraordinary that they fully understand the implementation of mpl or proto and that they simply do not understand that mediocre programmers as me (sorry for "only" 15 years of C++ experience) stumble over questions on a much lower level.
I enjoyed this and other threads and some comments in the docs that simply tell me I am an absolute beginner. For me reference docs are helpful when I am through the normal docs, not as a first contact.
Please note that I hesitate to blame Steven for the fact that the docs do not meet my needs. I expect TypeErasure to be a great library with a near- perfect and well-thought implementation, only the missing step-by-step intro is exactly my problem with this library. I can imagine that writing it should not be Steven's burden. Like for the STL which was not written by
IMO, users can/should fully expect the library authors to put as much effort in the documentation as in the library design and implementation.
Scott Meyers, but only perfectly explained.
@Steven:
If you have some more examples at hand, please insert them into the examples section.
If you have some silly little example of the problem the library solves, please put it into the introduction chapter. People might read the library description and not get a clue what it was meant for.
I suggested something like the example below to be added to the Introduction section: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... #include <boost/type_erasure/any.hpp> #include <boost/type_erasure/builtin.hpp> #include <boost/type_erasure/operators.hpp> #include <boost/mpl/vector.hpp> #include <iostream> struct display { public: template< typename T > explicit display ( T const& obj ) : obj_(obj) {} public: void print ( void ) { std::cout << obj_ << std::endl; } public: boost::type_erasure::any< boost::mpl::vector< boost::type_erasure::copy_constructible<> , boost::type_erasure::ostreamable<> > > obj_; }; int main ( void ) { display i(-1), d('x'); i.print(); d.print(); return 0; } I had to do something like this in the past where: 1. I didn't want display to be a template but I wanted it to handle generic types as passed to the constructor. 2. I knew a-priori the operations that display needed from T (e.g., operator<<). 3. I had to store the object of the generic type T so the operation on T could be performed later (e.g., by print). And Steven commented: On Tue, Jun 19, 2012 at 12:12 AM, Steven Watanabe <watanabesj@gmail.com> wrote:
This is a textbook use case for the library. Use TypeErasure states the intent of the code clearly. obj_ can hold any type that is CopyConstructible, and Ostreamable.
Right after this example, the Introduction section could note how Boost.TypeErasure generalize of Boost.Any, Boost.Function, and Boost.AnyIterator thus applying to the problem domain of these existing libraries in a more general sense -- respectively: any<mpl::vector<copy_constructible<>, typeid_<> > > // any any<mpl::vector<copy_constructible<>, typeid_<>, callable<void(int)> >
// function any<mpl::vector<forward_iterator<>, same_type<forward_iterator<>::value_type, int> > > // any iterator
All of this (example included) might be a good addition to the Introduction section. HTH, --Lorenzo

On 07/22/12 20:59, Lorenzo Caminiti wrote: [snip]
I suggested something like the example below to be added to the Introduction section: [snip] I'd suggest adding something like the attached to:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/... This would emphasize that using tuple is a shorthand way of doing something similar with bindings. IOW, the code in the attached starting with: //Something similar using bindings and just any's. does something similar to the code starting with: //Illustrate doing a operator+ starting from tuple. HTH. -regards, Larry

On 7/22/2012 8:18 AM, Markus Werle wrote:
Here I am in the same situation as with proto: I will read the docs again and again and not really get sure about whether I am doing it right.
<weeps> Proto's pdf docs are nearly 400 pages long! -- not that that necessarily means anything. Nevertheless, it's vexing that people still find the documentation lacking. Where are you stumbling? Do you have any concrete suggestions for how I could improve things? "Tutorials," isn't a concrete suggestion. Something like, "I read X in the docs and didn't understand it," or "I am trying to do Y and I can't figure out how," would be more helpful. Thanks in advance, -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler wrote:
On 7/22/2012 8:18 AM, Markus Werle wrote:
Here I am in the same situation as with proto: I will read the docs again and again and not really get sure about whether I am doing it right.
<weeps> Proto's pdf docs are nearly 400 pages long! -- not that that necessarily means anything. Nevertheless, it's vexing that people still find the documentation lacking.
</weeps> I had hoped that I come through with my message that I do not want to make you responsible for this or blame anyone.
Where are you stumbling? Do you have any concrete suggestions for how I could improve things? "Tutorials," isn't a concrete suggestion. Something like, "I read X in the docs and didn't understand it," or "I am trying to do Y and I can't figure out how," would be more helpful.
Thanks in advance,
I digged through the docs multiple times but I always get stuck with grammars and transforms and callable transforms. Unfortunately I had to switch to C# during the day and taking control over proto is not something that can be done at midnight. I will post questions again in my next attempt to approach proto. Markus

On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
[snip] The 1st attachment, composed from above, doesn't compile, giving errors in 2nd attachment. svn update shows: Updated to revision 79597. How should the code be changed to allow compilation? TIA. -regards, Larry

On 07/19/12 06:08, Larry Evans wrote:
On 07/18/12 01:29, Vicente J. Botet Escriba wrote:
Hi,,
In the example from the doc
typedef mpl::vector< copy_constructible<_a>, copy_constructible<_b>, copy_constructible<_c>, constructible<_a(const _b&, const _c&)> > construct;
std::vector<double> vec; int i = 10; double d = 2.5; tuple<construct, _a&, _b, _c> t(vec, i, d); any<construct, _a> v(get<1>(t), get<2>(t));
[snip] The 1st attachment, composed from above, doesn't compile, giving errors in 2nd attachment.
svn update shows:
Updated to revision 79597.
How should the code be changed to allow compilation?
It compiles OK when the -std=gnu++11 option is removed. However, it's still producing warnings like: ../../../boost/type_erasure/detail/adapt_to_vtable.hpp: In static member function 'static R boost::type_erasure::detail::vtable_adapter<PrimitiveConcept, R()>::value()': ../../../boost/type_erasure/detail/adapt_to_vtable.hpp:236:11: warning: typedef 'traits' locally defined but not used [-Wunused-local-typedefs] > traits; ^ In file included from botet_construct.cpp:6:0: ../../../boost/type_erasure/any_cast.hpp: In function 'T boost::type_erasure::any_cast(const boost::type_erasure::any<Concept, Tag>&)': ../../../boost/type_erasure/any_cast.hpp:132:13: warning: typedef 'tag_type' locally defined but not used [-Wunused-local-typedefs] >::type tag_type; ^ This is with compiler: ftp://gcc.gnu.org/pub/gcc/snapshots/4.8-20120624/gcc-4.8-20120624.tar.bz2 -regards, Larry

AMDG On 07/19/2012 04:08 AM, Larry Evans wrote:
The 1st attachment, composed from above, doesn't compile, giving errors in 2nd attachment.
svn update shows:
Updated to revision 79597.
How should the code be changed to allow compilation?
This should be fixed in r79602, but I'd still advise against compiling in C++11 mode right now. I haven't tested it nearly as much as the C++03 implementation. In Christ, Steven Watanabe
participants (9)
-
Eric Niebler
-
Fabio Fracassi
-
Larry Evans
-
lcaminiti
-
Lorenzo Caminiti
-
Markus Werle
-
Steven Watanabe
-
Vicente Botet
-
Vicente J. Botet Escriba