Boost logo

Boost :

Subject: Re: [boost] [TypeErasure] Forward constructors and binded types
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-07-19 10:36:40

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&lt;construct, _a&amp;amp;, _b, _c&gt; t1(vec, i, d);
>>>> tuple&lt;construct, _a&amp;amp;, _b, _c&gt; t2(x, i, d);
>>>> any&lt;construct, _a&gt; v1(get<1>(t1), get<2>(t1));
>>>> any&lt;construct, _a&gt; 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:

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:


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:


supporting the above conclusion.

Do the docs say anywhere that this is what
happens when 2 different bindings are used
to construct something?


Boost list run by bdawes at, gregod at, cpdaniel at, john at