[TypeErasure] Forward constructors and binded types

classic Classic list List threaded Threaded
33 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[TypeErasure] Forward constructors and binded types

Vicente Botet
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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

cppljevans
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/doc/html/boost_typeerasure/multi.html

>
>     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



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
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/doc/html/boost_typeerasure/multi.html
>
>>
>>     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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Vicente Botet
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/doc/html/boost_typeerasure/multi.html
>
>>
>>     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
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Vicente Botet
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/doc/html/boost_typeerasure/multi.html
>
>>
>>     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
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
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/doc/html/boost_typeerasure/multi.html
>>>>
>>>>>
>>>>>     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&lt;construct, _a&amp;, _b, _c&gt; t(vec, i, d);
>>>>>     any&lt;construct, _a&gt; 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Vicente Botet
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/doc/html/boost_typeerasure/multi.html
>>>>
>>>>>
>>>>>     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
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
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/doc/html/boost/type_erasure/any.html#id2370327-bb

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Vicente Botet
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/doc/html/boost/type_erasure/any.html#id2370327-bb
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
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
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&amp;, _b, _c> t1(vec, i, d);
>     tuple<construct, _a&amp;, _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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Vicente Botet
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&amp;, _b, _c> t1(vec, i, d);
>     tuple<construct, _a&amp;, _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

 

Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

cppljevans
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.

-regards,
Larry



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Fabio Fracassi
In reply to this post by Steven Watanabe-4
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/doc/html/boost_typeerasure/multi.html
>>
>>>
>>>      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






_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

lcaminiti
In reply to this post by cppljevans
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/doc/html/boost_typeerasure/reference.html#header.boost.type_erasure.tuple_hpp

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
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
In reply to this post by Fabio Fracassi
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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

cppljevans
In reply to this post by Vicente Botet
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



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

botet_construct.cpp (822 bytes) Download Attachment
botet_construct.out (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

cppljevans
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




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

cppljevans
In reply to this post by cppljevans
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:


http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/example/construction.cpp

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



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

construction.cpp (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
AMDG

On 07/19/2012 07:36 AM, Larry Evans wrote:

>
>
> http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/example/construction.cpp
>
> 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/doc/html/boost/type_erasure/any.html#id2370327-bb

"The bindings of all the arguments that are any's, must be the same."

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: [TypeErasure] Forward constructors and binded types

Steven Watanabe-4
In reply to this post by cppljevans
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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
12