On Mon, Mar 9, 2015 at 4:29 PM, Steven Watanabe
AMDG
On 03/09/2015 03:04 PM, Matt Calabrese wrote:
Awesome. I haven't looked at the implementation and haven't thought about the problem enough, so forgive me if this is a silly question -- why is
it
that register_binding needs to be invoked *manually*? In other words, why can't the instantiation of dynamic_any_cast do something like examine the types of all of the concepts involved, then force an instantiation of a template for each of those concept types, which would perform the registration?
dynamic_any_cast cannot do this registration because it only knows the source and destination concepts. It knows the contained type at *runtime* via std::type_info, which isn't suitable for template instantiations.
Ah, I didn't notice the void(*)() part in the example binding (which is the target type). I think I understand a bit better now. When I first looked at the example I though you just needed to register the concepts for some reason. 1) You don't pay for what you don't use. Putting
the registration in the constructor means that it will always happen whether it's needed or not. 2) It still won't catch everything. In the example I posted, the object is captured by an any type which does not support callable, and later cast to another any type which does. The constructor will therefore not instantiate callable
. I think that explicit manual registration is less likely to to cause hard to find bugs that automatic registration that only works most of the time.
Okay, this facility is much different from what I thought it was. I should
have looked at the example code more closely before replying. I read the
description and thought it was for the following type of situation:
//////////
void foo() {}
function_any