[Fusion, maybe?] Workings of ADL.

I expected this to work #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/at_c.hpp> typedef boost::fusion::vector<int, int> V; int first( const V & v ) { return at_c<0>( v ); } but I find I need a "using namespace boost::fusion;". Why isn't this covered by ADL? Thx - Rob.

AMDG Robert Jones wrote:
I expected this to work
#include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/at_c.hpp>
typedef boost::fusion::vector<int, int> V;
int first( const V & v ) { return at_c<0>( v ); }
but I find I need a "using namespace boost::fusion;". Why isn't this covered by ADL?
When calling a function template with explicit template arguments, ADL is only activated if at least one overload is found by normal lookup. In Christ, Steven Watanabe

On Wed, Sep 8, 2010 at 2:48 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
Robert Jones wrote:
I expected this to work
#include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/at_c.hpp>
typedef boost::fusion::vector<int, int> V;
int first( const V & v ) { return at_c<0>( v ); }
but I find I need a "using namespace boost::fusion;". Why isn't this covered by ADL?
When calling a function template with explicit template arguments, ADL is only activated if at least one overload is found by normal lookup.
Thanks for that Steven - could you possibly give me a C++ Standard reference for that? Thx, Rob.

AMDG Robert Jones wrote:
On Wed, Sep 8, 2010 at 2:48 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
When calling a function template with explicit template arguments, ADL is only activated if at least one overload is found by normal lookup.
Thanks for that Steven - could you possibly give me a C++ Standard reference for that?
14.8.1/6: "... But when a function template with explicit template arguments is used, the call does not have the correct syntactic form unless there is a function template with that name visible at the point of the call...." In Christ, Steven Watanabe

On Wed, Sep 8, 2010 at 5:57 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
Robert Jones wrote:
On Wed, Sep 8, 2010 at 2:48 PM, Steven Watanabe <watanabesj@gmail.com
wrote:
When calling a function template with
explicit template arguments, ADL is only activated if at least one overload is found by normal lookup.
Thanks for that Steven - could you possibly give me a C++ Standard reference for that?
14.8.1/6: "... But when a function template with explicit template arguments is used, the call does not have the correct syntactic form unless there is a function template with that name visible at the point of the call...."
Once again thank you Steven - I've found the reference, in particular the very clear example, but the rationale behind it eludes me! - Rob.

On Wed, Sep 8, 2010 at 5:57 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
14.8.1/6: "... But when a function template with explicit template arguments is used, the call does not have the correct syntactic form unless there is a function template with that name visible at the point of the call...."
That is just the oddest rule! Going back to my original example, I could make it work just by adding an arbritary declaration of at_c(), #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/at_c.hpp> typedef boost::fusion::vector<int, int> V; template <typename T, typename U> void at_c( const U & ); int first( const V & v ) { return at_c<0>( v ); } which doesn't even need to be defined anywhere. If such a namespace-enabling template were to be removed, thus breaking the look-up used in my 'first()' function it would be a horrible bug to find! - Rob.

AMDG Robert Jones wrote:
On Wed, Sep 8, 2010 at 5:57 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
14.8.1/6: "... But when a function template with explicit template arguments is used, the call does not have the correct syntactic form unless there is a function template with that name visible at the point of the call...."
That is just the oddest rule! Going back to my original example, I could make it work just by adding an arbritary declaration of at_c(),
#include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/at_c.hpp>
typedef boost::fusion::vector<int, int> V;
template <typename T, typename U> void at_c( const U & );
int first( const V & v ) { return at_c<0>( v ); }
which doesn't even need to be defined anywhere. If such a namespace-enabling template were to be removed, thus breaking the look-up used in my 'first()' function it would be a horrible bug to find!
I think the rationale is that the the compiler needs to know that at_c is a template in order to parse the expression. It's basically the same reason we need to use template and typename to disambiguage. In Christ, Steven Watanabe
participants (2)
-
Robert Jones
-
Steven Watanabe