[boost] [type_erasure] Review started (July 18-27, 2012)
Hello all, *** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. *** THE LIBRARY C++ provides runtime polymorphism through virtual functions. They are a very useful feature, but they do have some limitations. * They are intrusive. In generic programming, we can design an interface which allows third-party types to be adapted to it. * They require dynamic memory management. Of course, most of the problems can be avoided by using an appropriate smart pointer type. Even so, it still acts like a pointer rather than a value. * Virtual functions' ability to apply multiple independent concepts to a single object is limited. The Boost.TypeErasure library solves these problems allowing us to mirror static generic programming at runtime. Library source: http://svn.boost.org/svn/boost/sandbox/type_erasure/ Pre-built documentation: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/ You can also download archives with pre-built documentation from: http://sourceforge.net/projects/steven-watanabe.u/files/ YOUR REVIEW Please submit a review to the mailing-list by replying to this email ("[boost] [type_erasure] Review ..." should be in the subject). Please state clearly whether you think this library should be accepted as a Boost library. Other questions you may want to consider: 1. What is your evaluation of the design? 2. What is your evaluation of the implementation? 3. What is your evaluation of the documentation? 4. What is your evaluation of the potential usefulness of the library? 5. Did you try to use the library? With what compiler? Did you have any problems? 6. How much effort did you put into your evaluation? A glance? A quick reading? In-depth study? 7. Are you knowledgeable about the problem domain? Thanks in advance to all who participate in the review discussion -- I'm looking forward to it! The review manager. --Lorenzo
Hello all,
On Wed, Jul 18, 2012 at 1:13 AM, Lorenzo Caminiti
*** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. ***
*** Boost.TypeErasure review ends in 5 days. Please submit your reviews :D *** There have been interesting discussions on the library on the ML but I have not received any official review yet :( Especially if you are a user of Boost Any, Function, and Any Iterator, you definitely want to take a look at Type Erasure as it generalizes solutions provided by those other libraries. Thank you. The review manager. --Lorenzo
THE LIBRARY
C++ provides runtime polymorphism through virtual functions. They are a very useful feature, but they do have some limitations. * They are intrusive. In generic programming, we can design an interface which allows third-party types to be adapted to it. * They require dynamic memory management. Of course, most of the problems can be avoided by using an appropriate smart pointer type. Even so, it still acts like a pointer rather than a value. * Virtual functions' ability to apply multiple independent concepts to a single object is limited. The Boost.TypeErasure library solves these problems allowing us to mirror static generic programming at runtime.
Library source: http://svn.boost.org/svn/boost/sandbox/type_erasure/
Pre-built documentation: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/
You can also download archives with pre-built documentation from: http://sourceforge.net/projects/steven-watanabe.u/files/
YOUR REVIEW
Please submit a review to the mailing-list by replying to this email ("[boost] [type_erasure] Review ..." should be in the subject).
Please state clearly whether you think this library should be accepted as a Boost library.
Other questions you may want to consider: 1. What is your evaluation of the design? 2. What is your evaluation of the implementation? 3. What is your evaluation of the documentation? 4. What is your evaluation of the potential usefulness of the library? 5. Did you try to use the library? With what compiler? Did you have any problems? 6. How much effort did you put into your evaluation? A glance? A quick reading? In-depth study? 7. Are you knowledgeable about the problem domain?
Thanks in advance to all who participate in the review discussion -- I'm looking forward to it!
Lorenzo wrote:
Hello all, *** Boost.TypeErasure review ends in 5 days. Please submit your reviews :D
Library source: http://svn.boost.org/svn/boost/sandbox/type_erasure/
Just in case any other Boost SVN neophytes like me trying to get hold of this - I'm finding that http anonymous access is not available, however https access does work. The URL is otherwise identical.
This is my review of the type erasure library following a relatively brief
look at it.
0) I vote to accept the library into Boost
1) Evaluation of design
I like it. The central class, any< mpl::vector< .. > >, is exactly what I'd
expect.
It is a mild shame that the notation for references is the old and familiar
boost::ref() style as used in several other Boost libraries, but accept this
is not technically possible.
2) Evaluation of implementation.
Not evaluated.
3) Evaluation of documentation.
As others have said, further examples will lower the learning curve.
Although the references section looks forbidding at first, my gut feel is
that it will be like other Boost libraries - the reference section only
"comes alive" when you know the library quite well and you just need to
remind yourself what is (and what isn't) available.
4) Usefulness
I think this enormous potential and would be very likely to use it my own
code. I've several times found that it would be nice to generalize
boost::function or adobe::any_iterator but never had the wherewithal to do
it well. For example a library I've been involved in had its own notion of a
"multi_function" like a boost::function<> but all instances had to support
multiple function signatures, This turned out to be almost trivial with
Boost.TypeErasure. A complete program listing follows:
#include
multi_function_concepts;
5. Did you try to use the library? With what compiler? Did you have any
typedef any< multi_function_concepts , _self > non_ref_multi_function; typedef any< multi_function_concepts , _self& > ref_multi_function; template<typename RefInfo> double test_multi_function( any< multi_function_concepts , RefInfo > const& mf ) { return mf(3.0) + mf(1.0,2.0); } struct model_of_multi_function { typedef double state_t; state_t m_state; explicit model_of_multi_function(state_t state) : m_state(state) { } double operator()(double x) const { return m_state + x; } double operator()(double x, double y) const { return m_state*x*y; } }; int main() { model_of_multi_function m(5.0); non_ref_multi_function x( m ); ref_multi_function y(m); std::cout << "Result1 was : " << test_multi_function(x) << "\n"; std::cout << "Result2 was : " << test_multi_function(y) << "\n"; m.m_state = 6.0; //should not change state of x, should change state of y std::cout << "Result3 was : " << test_multi_function(x) << "\n"; std::cout << "Result4 was : " << test_multi_function(y) << "\n"; } problems? Yes I tried to used the library to prove "multi_function" worked as above. Compiled and ran only with VC10 - no problems to report.
6. How much effort did you put into your evaluation? A glance? A quick reading? In-depth study?
About 3 hours in total: playing with library, reading docs, reading test code.
7. Are you knowledgeable about the problem domain?
Only in so much that I'm one of many to think "what is the true generalization of Boost.Function??". From my look this evening, Boost.TypeErasure appears to be it. One final point on the name. Paul Bristow wrote:
PS I can't come up with a better name than TypeErasure but it is certainly a bit forbidding :-)
I'd like to respectively disagree. My intuition notion of what the library
might be about having only heard the name turned out to match exactly with
what it can really do. That suggests it is a good name!
-----Original Message-----
From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org]
On Behalf Of Lorenzo Caminiti
Sent: 23 July 2012 2:10 PM
To: boost@lists.boost.org; boost-announce@lists.boost.org;
boost-users@lists.boost.org
Subject: Re: [boost] [type_erasure] Review started (July 18-27, 2012)
Hello all,
On Wed, Jul 18, 2012 at 1:13 AM, Lorenzo Caminiti
*** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. ***
*** Boost.TypeErasure review ends in 5 days. Please submit your reviews :D *** There have been interesting discussions on the library on the ML but I have not received any official review yet :( Especially if you are a user of Boost Any, Function, and Any Iterator, you definitely want to take a look at Type Erasure as it generalizes solutions provided by those other libraries. Thank you. The review manager. --Lorenzo
THE LIBRARY
C++ provides runtime polymorphism through virtual functions. They are a very useful feature, but they do have some limitations. * They are intrusive. In generic programming, we can design an interface which allows third-party types to be adapted to it. * They require dynamic memory management. Of course, most of the problems can be avoided by using an appropriate smart pointer type. Even so, it still acts like a pointer rather than a value. * Virtual functions' ability to apply multiple independent concepts to a single object is limited. The Boost.TypeErasure library solves these problems allowing us to mirror static generic programming at runtime.
Library source: http://svn.boost.org/svn/boost/sandbox/type_erasure/
Pre-built documentation:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/
You can also download archives with pre-built documentation from: http://sourceforge.net/projects/steven-watanabe.u/files/
YOUR REVIEW
Please submit a review to the mailing-list by replying to this email ("[boost] [type_erasure] Review ..." should be in the subject).
Please state clearly whether you think this library should be accepted as a Boost library.
Other questions you may want to consider: 1. What is your evaluation of the design? 2. What is your evaluation of the implementation? 3. What is your evaluation of the documentation? 4. What is your evaluation of the potential usefulness of the library? 5. Did you try to use the library? With what compiler? Did you have any problems? 6. How much effort did you put into your evaluation? A glance? A quick reading? In-depth study? 7. Are you knowledgeable about the problem domain?
Thanks in advance to all who participate in the review discussion -- I'm looking forward to it!
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On 07/18/12 00:13, Lorenzo Caminiti wrote:
Hello all,
*** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. *** [snip] http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
contains a link, named boost::any, which sends my browser to: http://steven_watanabe.users.sourceforge.net/type_erasure/libs/any/index.htm... and that page shows: An error has been encountered in accessing this page. 1. Server: steven_watanabe.users.sourceforge.net 2. URL path: /type_erasure/libs/any/index.html 3. Error notes: NONE 4. Error type: 404 5. Request method: GET 6. Request query string: NONE 7. Time: 2012-07-23 19:27:19 UTC (1343071639)
AMDG On 07/23/2012 12:37 PM, Larry Evans wrote:
On 07/18/12 00:13, Lorenzo Caminiti wrote:
Hello all,
*** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. *** [snip] http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
contains a link, named boost::any, which sends my browser to:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/any/index.htm...
The link would be correct if the library were dropped into a boost distribution. I'm ignoring this problem for now. In Christ, Steven Watanabe
On 07/18/12 00:13, Lorenzo Caminiti wrote:
Hello all,
*** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. ***
The page:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/...
says:
x is approximately equivalent to a boost::any
however, it doesn't say how te::any differs from boost::any.
The attached shows that a boost::any can change it's
type, and, as such, is somewhat like boost::variant.
However, te::any, once it's created, cannot change
it's type, AFAICT. At least that's what the
attached code indicates when compiled with:
#define SHOW_TE_FIXED_TYPE
With that #define, the error produced by gcc4.8 is:
../../../boost/type_erasure/any.hpp:702:9: note: mismatched types
'const boost::type_erasure::assignable
This isn't a review, mainly because I don't feel qualified to offer one, just a comment. I don't really understand what difficulty this library is intended to solve, I've read the comments about begin a generalisation of Any and Function, and Eric's naming suggestions of Boost.Duck etc, but a single a example of coding conundrum for which this library is a better, or only, solution would be hugely helpful. Thanks, Rob.
On 07/18/12 00:13, Lorenzo Caminiti wrote:
Hello all,
*** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. *** [snip] Should type_erasure be accepted into Boost?
Answer:
No, not yet.
Why(in order of importance):
1) any
struct v
{
};
int main()
{
typedef
mpl::vector
< copy_constructible<_a>
#define COPY_CTOR_V0
#ifdef COPY_CTOR_V0
, constructible<_a(v<0>const&)>
//allows y(a_binding, v0)
//(see below) to compile.
#endif
>
a_concept;
typedef
any
< a_concept
, _a
>
a_any;
v<0>
v0;
a_any
x
( v0
)
/**
* This CTOR does no dispatching, it simply
* calls the decltype(v0) CTOR with argument, v0.
*
* This is a binding constructor, as defined in [ConsKind].
*/
;
binding
[any.hpp mysterious false?exp1:exp2 expr]:
In any.hpp, there's several expressions like:
false? this->_boost_type_erasure_deduce_constructor(arg...) : 0
Since:
false?exp1:exp2
always evaluates to exp2, this just obscures the code. It should be replaced with exp2(i.e. 0) or some in-source comment attached explaining why the ?: operator is needed.
This use of the conditional operator is a technique to determine the type of an expression without evaluating it. In this case, "arg..." will never be evaluated (since it appears in a false branch of a conditional expression), but its type will influence the type of the entire conditional expression. Eric Niebler explains this technique nicely in this article [1] (see page 2 in particular). Regards, Nate [1] http://www.artima.com/cppsource/foreach.html
On 08/03/12 02:04, Nathan Ridge wrote:
[any.hpp mysterious false?exp1:exp2 expr]:
In any.hpp, there's several expressions like:
false? this->_boost_type_erasure_deduce_constructor(arg...) : 0
Since:
false?exp1:exp2
always evaluates to exp2, this just obscures the code. It should be replaced with exp2(i.e. 0) or some in-source comment attached explaining why the ?: operator is needed.
This use of the conditional operator is a technique to determine the type of an expression without evaluating it. In this case, "arg..." will never be evaluated (since it appears in a false branch of a conditional expression), but its type will influence the type of the entire conditional expression.
Eric Niebler explains this technique nicely in this article [1] (see page 2 in particular).
Regards, Nate
THANK YOU! If any.hpp had used a macro, somewhat like the ENCODED_TYPEOF shown here: http://www.artima.com/cppsource/foreach2.html including the comments explaining the purpose, the code would have been easier to understand. -regards, Larry with either the
Hello,
Just some questions:
1) Missing #include <cassert> in "boost\type_erasure\detail\storage.hpp"
2) Maybe i'm missing something, but it feels like the library doesn't
support concept function arguments an return types that contain
placeholder as a template parameter. Imagine a concept that returns
"std::pair
5. Did you try to use the library? With what compiler? Did you have any problems?
MSVC 9.0
6. How much effort did you put into your evaluation? A glance? A quick reading? In-depth study?
Several hours.
7. Are you knowledgeable about the problem domain?
Almost no. -- ------------ Sergey Mitsyn.
AMDG On 08/03/2012 02:32 PM, Sergey Mitsyn wrote:
Hello,
Just some questions:
1) Missing #include <cassert> in "boost\type_erasure\detail\storage.hpp"
This header doesn't use assert.
2) Maybe i'm missing something, but it feels like the library doesn't support concept function arguments an return types that contain placeholder as a template parameter. Imagine a concept that returns "std::pair
", where TIterator is another any: template
struct foo_concept { typedef std::pair result_type; static result_type apply(C& c) { return std::make_pair(c.begin(),c.end()); } }; Probably the problem is with detail::rebind_placeholders_in_argument. The expected behavior is replacing 'TIterator' with something like 'std::_Vector_iterator' (or what it should be in specific case), just like mpl::lambda replaces its mpl::_N placeholders.
Also I cannot just replace std::pair with another any - I'm trying to match the preexisting concepts.
I've put an example into attachment.
The library can't handle this without
special knowledge of std::pair. This
would mean creating some kind of extension
point, which I'm not willing to do at this point.
The easiest way to handle this particular
case is to use output parameters
template
On 04.08.2012 16:46, Steven Watanabe wrote:
AMDG
On 08/03/2012 02:32 PM, Sergey Mitsyn wrote:
Hello,
Just some questions:
1) Missing #include <cassert> in "boost\type_erasure\detail\storage.hpp"
This header doesn't use assert.
Sorry, my fault - being messing with headers a little.
2) Maybe i'm missing something, but it feels like the library doesn't support concept function arguments an return types that contain placeholder as a template parameter. Imagine a concept that returns "std::pair
", where TIterator is another any: template
struct foo_concept { typedef std::pair result_type; static result_type apply(C& c) { return std::make_pair(c.begin(),c.end()); } }; Probably the problem is with detail::rebind_placeholders_in_argument. The expected behavior is replacing 'TIterator' with something like 'std::_Vector_iterator' (or what it should be in specific case), just like mpl::lambda replaces its mpl::_N placeholders.
Also I cannot just replace std::pair with another any - I'm trying to match the preexisting concepts.
I've put an example into attachment.
The library can't handle this without special knowledge of std::pair. This would mean creating some kind of extension point, which I'm not willing to do at this point.
Why is that? AFAIK it's rather easy to determine class template and template arguments from its instantiation - by passing it to specialized class template. The "recursive" argument rebinding comes out naturally. Is there another problem?
The easiest way to handle this particular case is to use output parameters
template
struct foo_concept { static void apply(C&, TIterator&, TIterator&); };
Ok. Adapting to std::pair
In Christ, Steven Watanabe
-- ------------ Sergey Mitsyn.
The library can't handle this without special knowledge of std::pair. This would mean creating some kind of extension point, which I'm not willing to do at this point.
Why is that? AFAIK it's rather easy to determine class template and template arguments from its instantiation - by passing it to specialized class template. The "recursive" argument rebinding comes out naturally.
Is there another problem?
Ok, probably I got it. Library needs to pass anys as void*, and it's
impossible to say how to convert arbitrary C
participants (7)
-
Larry Evans
-
Lorenzo Caminiti
-
Nathan Ridge
-
Pete Bartlett
-
Robert Jones
-
Sergey Mitsyn
-
Steven Watanabe