Portál AbcLinuxu, 23. dubna 2024 18:57


Dotaz: C++ porting to Clang : templates & namespace lookup

25.6.2013 16:21 breznak
C++ porting to Clang : templates & namespace lookup
Přečteno: 454×
Odpovědět | Admin

Zdravim,

upravuji kod pro modelovani neuronovych siti jako v neokortexu a snazim se pridat podporu pro Clang.

Potreboval bych poradit s porovnanim templatu a namespace v C++.

Kod, o kterem mluvim je k nahlednuti zde: https://github.com/breznak/nupic/tree/compilation .

Zde je vystup pri prekladu s chybou:

In file included from
/home/marek/devel/nupic/nta/algorithms/SparsePooler.cpp:28:
In file included from
/home/marek/devel/nupic/nta/algorithms/SparsePooler.hpp:40:
/home/marek/devel/nupic/nta/math/stl_io.hpp:514:20: error: call to function
'operator<<' that is neither visible in the template definition nor found
by argument-dependent
      lookup
        out_stream << v[i] << ' ';
                   ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:532:11: note: in instantiation
of member function 'nta::vector_saver<std::vector<std::pair<unsigned int,
unsigned int>,
      std::allocator<std::pair<unsigned int, unsigned int> > >,
false>::save' requested here
    saver.save(n, out_stream, v);
          ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:542:5: note: in instantiation
of function template specialization
'nta::vector_save<std::vector<std::pair<unsigned int, unsigned
      int>, std::allocator<std::pair<unsigned int, unsigned int> > > >'
requested here
    vector_save(v.size(), out_stream, v);
    ^
/home/marek/devel/nupic/nta/algorithms/SparsePooler.cpp:79:39: note: in
instantiation of function template specialization
'nta::operator<<<std::vector<std::pair<unsigned int,
      unsigned int>, std::allocator<std::pair<unsigned int, unsigned int> >
> >' requested here
    outStream << segmentSize() << " " << masks_ << " ";
                                      ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:540:24: note: 'operator<<'
should be declared prior to the call site
  inline std::ostream& operator<<(std::ostream& out_stream, const
std::vector<T>& v)
                       ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:430:19: error: call to function
'operator>>' that is neither visible in the template definition nor found
by argument-dependent
      lookup
        in_stream >> v[i];
                  ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:443:12: note: in instantiation
of member function 'nta::vector_loader<std::vector<std::pair<unsigned int,
unsigned int>,
      std::allocator<std::pair<unsigned int, unsigned int> > >,
false>::load' requested here
    loader.load(n, in_stream, v);
           ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:558:5: note: in instantiation
of function template specialization
'nta::vector_load<std::vector<std::pair<unsigned int, unsigned
      int>, std::allocator<std::pair<unsigned int, unsigned int> > > >'
requested here
    vector_load(n, in_stream, v);
    ^
/home/marek/devel/nupic/nta/algorithms/SparsePooler.cpp:85:49: note: in
instantiation of function template specialization
'nta::operator>><std::vector<std::pair<unsigned int,
      unsigned int>, std::allocator<std::pair<unsigned int, unsigned int> >
> >' requested here
    inStream >> segment_size_ >> general_vector >> masks_;
                                                ^
/home/marek/devel/nupic/nta/math/stl_io.hpp:553:3: note: 'operator>>'
should be declared prior to the call site
  operator>>(std::istream& in_stream, std::vector<T>& v)
  ^
3 warnings and 2 errors generated.
make[2]: *** [libalgorithms_a-SparsePooler.o] Error 1
make[2]: Leaving directory `/tmp/ntabuild/nta/algorithms'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/tmp/ntabuild/nta'
make: *** [install-recursive] Error 1

V podstate navod na reseni je podle meho tady http://clang.llvm.org/compatibility.html#dep_lookup , ale nevim, jak ho pouzit pro tento pripad :)

Zatim jsem se ptal na ML (anglicky) http://lists.numenta.org/pipermail/nupic_lists.numenta.org/2013-June/000398.html , ale bez odpovedi..

Budu moc rad, pokud mi nejaky zkusenejsi C++ programator poradi!

Diky, Marek

Nástroje: Začni sledovat (1) ?Zašle upozornění na váš email při vložení nového komentáře.

Odpovědi

25.6.2013 23:57 Luky
Rozbalit Rozbalit vše Re: C++ porting to Clang : templates & namespace lookup
Odpovědět | | Sbalit | Link | Blokovat | Admin
Skusil som skompilovat vzorovy kod s funkciou Multiply z odkazu http://clang.llvm.org/compatibility.html#dep_lookup a nepodarilo sa mi ho skompilovat ani s g++ 4.7.3 ani s clang++ 3.0

Po zmene poradia sa uz kod skopiloval s oboma kompilatormi
int Multiply(int x, int y) {
      return x * y;
}

template <typename T> T Squared(T x) {
      return Multiply(x, x);
}

int main() {
      return Squared(5);
}
Dufam, ze Vam to pomoze.
26.6.2013 12:46 breznak
Rozbalit Rozbalit vše Re: C++ porting to Clang : templates & namespace lookup
Ahoj Luky, diky moc za radu! Tenhle problem jsem nejak vyresil, me trapi problem (v tom linku az nize, druha pulka), kde pretezuji operator << : template operator<< ... { a pak v tele pouzivam stejny op. << (cili asi std::<<, nebo tak neco..) } Tady prave (asi?) nejde dat template definici pred prvni pouziti.

Založit nové vláknoNahoru

Tiskni Sdílej: Linkuj Jaggni to Vybrali.sme.sk Google Del.icio.us Facebook

ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.