tags:

views:

66

answers:

1

hello.

I am baffled by the following name collision:

namespace mp2 {

boost::numeric::ublas::matrix_range<M>
slice(M& m, const R1& r1, const R2& r2) {
    namespace ublas = boost::numeric::ublas;
    ublas::range r1_(r1.begin(), r1.end()), r2_(r2.begin(), r2.end());
    return ublas::matrix_range<M>(m, r1_, r2_);
}

double energy(const Wavefunction &wf) {
    const Wavefunction::matrix& C = wf.coefficients();
    int No = wf.occupied().size();

    foreach (const Basis::MappedShell& P, basis.shells()) {
        slice(C, range(No), range(P));

the error from g++4.4 is

 7 In file included from mp2.cpp:1:
 8 /usr/include/boost/numeric/ublas/fwd.hpp: In function âdouble mp2::energy(const Wavefunction&)â:
 9 /usr/include/boost/numeric/ublas/fwd.hpp:32: error: âboost::numeric::ublas::sliceâ is not a function,
10 ../../src/mp2/energy.hpp:98: error:   conflict with âtemplate<class M, class R1, class R2> boost::numeric::ublas::matrix_range<M> mp2::slice(M&, const R1&, const R2&)â
11 ../../src/mp2/energy.hpp:123: error:   in call to âsliceâ
12 /usr/include/boost/numeric/ublas/fwd.hpp:32: error: âboost::numeric::ublas::sliceâ is not a function,
13 ../../src/mp2/energy.hpp:98: error:   conflict with âtemplate<class M, class R1, class R2> boost::numeric::ublas::matrix_range<M> mp2::slice(M&, const R1&, const R2&)â
14 ../../src/mp2/energy.hpp:129: error:   in call to âsliceâ
15 make: *** [mp2.lo] Error 1

ublas segment is

namespace boost { namespace numeric { namespace ublas {
    typedef basic_slice<> slice;

why is slice in ublas collides with slice in mp2? I and fairly certain there is no using namespace ublas in the code and in includes.

thank you

+2  A: 

I think there is argument-dependent lookup going on.

slice(C, range(No), range(P));

Two range arguments are seemingly from boost::numeric::ublas (probably imported with using boost::numeric::ublas::range;), so the compiler considers names form this namespace, which includes slice type in it.

Alex B