|
Boost : |
Subject: Re: [boost] [type_erasure] Some issues
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-02-25 12:13:10
AMDG
On 02/25/2013 08:45 AM, Fabio Fracassi wrote:
> Hi Steven,
>
> I recently gave a presentation about type erasure in general, and your
> library in particular, at our local C++ UG (see here
> http://prezi.com/kg6d82f-_yky/type-erasure/ or the examples at
> https://github.com/CppUGBerlin/Talks/tree/master/2013_02_19_TypeErasure
> if you are interested).
> During the preparation I discovered some issues I'd like to ask you about.
>
> First I think I discovered a bug either in your lib or in clang(with
> libc++) when compiling one of the documentation examples in C++11 mode.
>
I haven't tested much with clang in C++11 mode.
I wasn't able to get libc++ working on Linux.
Are you using the latest version: r83101?
Also, exactly what version of clang are you
using? I'll take a look at this later today.
> <snip>
>
> The next are some things which I didn't get to work, and the
> documentation is silent on any pitfalls.
>
> I tried to implement Sean Parent's example from his Value Semantics talk
> and failed to write a concept that calls free functions instead of
> members. Here is what I tried (full code and error at [2] below):
>
> template<class OBJ, class T>
> struct drawable {
> static void apply(const OBJ& obj, T& os, size_t pos) {
> draw(obj, os, pos);
> }
> };
>
> I get an error like: error call to function 'draw' that is neither
> visible in the template definition nor found by argument-dependent lookup
>
> I worked around this problem by defining a concept map, but that is not
> realy a good solution.
>
The problem is the way name lookup works. It's clear that
draw can't be found in the template definition, since it
isn't declared until later on. Argument dependent lookup
usually works, but in this case, the only associated namespace
is std (from std::ostream) and draw is defined in the global
namespace. (Note that the built-in types have no associated
namespaces). BOOST_TYPE_ERASURE_FREE will have exactly
the same problem. The solution is add declarations of draw
for all builtin types /before/ the definition of drawable.
> On researching a better solution I saw that you already added the
> convenience macros BOOST_TYPE_ERASURE_MEMBER and
> BOOST_TYPE_ERASURE_FREE, but didn't have much luck with them.
> Is there a compileable example where they are used somewhere?
>
libs/type_erasure/example/basic.cpp uses both.
See also libs/type_erasure/test/member.cpp
and libs/type_erasure/test/free.cpp.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk