Hi . I thought I'd try out VC8 as it is meant to conform very well to
the standard, however I am getting an error which would suggest that
ADL isnt being performed.
The relevent operator+ is defined in the same namespace as the types
and works in VC7.1,gcc3.2, gcc4 .
Has anyone any experience like this? Its not conforming surely. Note
that if I uncomment PUT_IN_OWN_NAMESPACE which puts func in the
namespace where the relevent types and oiperator+ are defined, then
everything works ok. Apologies that the full source code isnt here. I
tried on a class similar to std::complex and it didnt suffer this
problem.
#include <boost/pqs/t1_quantity/types/out/force.hpp>
#include <boost/pqs/t1_quantity/types/out/time.hpp>
// uncomment and this works
//#define PUT_IN_OWN_NAMESPACE
#ifdef PUT_IN_OWN_NAMESPACE
namespace boost{namespace pqs{
#endif
//using namespace boost::pqs; works
boost::pqs::force::N Func(
const boost::pqs::mass::kg & mass_in,
const boost::pqs::velocity::mm_div_s & initial_veloc,
const boost::pqs::velocity::m_div_s & final_veloc,
const boost::pqs::time::s & t)
{
final_veloc - initial_veloc;
boost::pqs::force::N result = mass_in * (final_veloc -
initial_veloc) / t;
return result;
}
#ifdef PUT_IN_OWN_NAMESPACE
}}
#endif
/* In vc8
..\test.cpp(21) : error C2676: binary '-' : 'const
boost::pqs::t1_quantity<AbstractQuantity,Units,Value_type>'
does not define this operator or a conversion to a type acceptable to
the predefined operator
with
[
AbstractQuantity=boost::pqs::meta::components::of_velocity::type,
Units=boost::pqs::meta::si_unit::none,
Value_type=boost::pqs::quantity_traits::default_value_type
]
*/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
andy199 (808)
|
1/22/2006 12:04:03 PM |
|
BTW putting stuff in the boost namespace is only because I'm trying to
write a boost library at the moment. Its not a general recommendation
to do that. I probably should have moved the stuff out for this
example. Sorry about that.
regards
Andy Little
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
kwikius
|
1/22/2006 8:53:41 PM
|
|
kwikius wrote:
> Hi . I thought I'd try out VC8 as it is meant to conform very well to
> the standard, however I am getting an error which would suggest that
> ADL isnt being performed.
> The relevent operator+ is defined in the same namespace as the types
> and works in VC7.1,gcc3.2, gcc4 .
>
> Has anyone any experience like this? Its not conforming surely. Note
> that if I uncomment PUT_IN_OWN_NAMESPACE which puts func in the
> namespace where the relevent types and oiperator+ are defined, then
> everything works ok. Apologies that the full source code isnt here. I
> tried on a class similar to std::complex and it didnt suffer this
> problem.
It's difficult to tell from your code fragment, because you are defining
some function Func, but the error refers to operator-. However, from
what I see I have the impression that VC8 is right: it *is* performing
ADL properly. That's because function Func can be found through ADL
*only* if you declare it in namespace boost::pqs and not if you declare
it in the global namespace.
What made you think VC8 is not conforming? Could you come up with a
smaller piece of source that shows the problem?
Ganesh
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Alberto
|
1/22/2006 10:56:36 PM
|
|
Alberto Ganesh Barbati wrote:
> kwikius wrote:
> > Hi . I thought I'd try out VC8 as it is meant to conform very well to
> > the standard, however I am getting an error which would suggest that
> > ADL isnt being performed.
> > The relevent operator+ is defined in the same namespace as the types
> > and works in VC7.1,gcc3.2, gcc4 .
> >
> > Has anyone any experience like this? Its not conforming surely. Note
> > that if I uncomment PUT_IN_OWN_NAMESPACE which puts func in the
> > namespace where the relevent types and oiperator+ are defined, then
> > everything works ok. Apologies that the full source code isnt here. I
> > tried on a class similar to std::complex and it didnt suffer this
> > problem.
>
> It's difficult to tell from your code fragment, because you are defining
> some function Func, but the error refers to operator-.
Sorry I havent been clear the only relevance of Func is that its a
function with a body. The real action is the two variables named
final_veloc and initial veloc with a subtraction between them. Those
two variable are actually typedefs in a container called of_velocity
which itself is in a namespace called ::boost::pqs::meta. The two
templated velocity types which the typedefs represent are defined in
::boost::pqs namespace together with their operations such as +- etc.
>However, from
> what I see I have the impression that VC8 is right: it *is* performing
> ADL properly. That's because function Func can be found through ADL
> *only* if you declare it in namespace boost::pqs and not if you declare
> it in the global namespace.
>
> What made you think VC8 is not conforming? Could you come up with a
> smaller piece of source that shows the problem?
I'll look at it again but very simple cases I came up with worked
properly.
Maybe the complexity of the types involved thats causing the problems.
It may be the fact that VC8 is one of a handful of compilers that is
conforming thats caught me, nevertheless it seems very odd that ADL
cant find operations defined in the same namespace as their types,
which is whats going on here.
regards
Andy Little
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
kwikius
|
1/23/2006 8:17:23 AM
|
|
kwikius wrote:
> Alberto Ganesh Barbati wrote:
>
> > kwikius wrote:
> > > Hi . I thought I'd try out VC8 as it is meant to conform very well to
> > > the standard, however I am getting an error which would suggest that
> > > ADL isnt being performed.
> > > The relevent operator+ is defined in the same namespace as the types
> > > and works in VC7.1,gcc3.2, gcc4 .
> > >
> > > Has anyone any experience like this? Its not conforming surely. Note
> > > that if I uncomment PUT_IN_OWN_NAMESPACE which puts func in the
> > > namespace where the relevent types and oiperator+ are defined, then
> > > everything works ok. Apologies that the full source code isnt here. I
> > > tried on a class similar to std::complex and it didnt suffer this
> > > problem.
> >
> > It's difficult to tell from your code fragment, because you are defining
> > some function Func, but the error refers to operator-.
There is definitely a problem in VC8. Unfortunately its not easy to
reproduce with simple types. In the following example compilation
succeeds dependent on various combinations of #FUNC1 and #FUNC2 . the
expressions in the two functions are equivalent but laid out
marginally differently.
regards
Andy Little
#include <boost/pqs/t1_quantity/types/out/velocity.hpp>
#include <boost/pqs/t1_quantity/types/out/mass.hpp>
#include <boost/pqs/t1_quantity/types/out/force.hpp>
#include <boost/pqs/t1_quantity/types/out/time.hpp>
#include <boost/pqs/t1_quantity/types/out/density.hpp>
#include <boost/pqs/t1_quantity/types/out/volume.hpp>
// of the two #defines below
// #define FUNC1 and FUNC2 --> compiles OK
// #define FUNC1 only --> compiles OK
// #define FUNC2 only --> error no '-' operator found
//#define FUNC1
#define FUNC2
#ifdef FUNC1
boost::pqs::force::N Func1(
const boost::pqs::mass::kg & mass_in,
const boost::pqs::velocity::mm_div_s& a,
const boost::pqs::velocity::m_div_s& b,
const boost::pqs::time::s & t)
{
boost::pqs::velocity::m_div_s v = a - b;
boost::pqs::force::N result = mass_in * v / t;
return result;
}
#endif
#ifdef FUNC2
boost::pqs::force::N Func2(
const boost::pqs::mass::kg & mass_in,
const boost::pqs::velocity::mm_div_s & a,
const boost::pqs::velocity::m_div_s& b,
const boost::pqs::time::s & t)
{
boost::pqs::force::N result = mass_in * (a-b) / t;
return result;
}
#endif
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
kwikius
|
1/25/2006 9:48:34 AM
|
|
|
4 Replies
117 Views
(page loaded in 0.11 seconds)
|