hi, template< typename T > class Static_object { public: .... template< typename... A > T *construct(A&&... args) { return new (_i) T(cxx::forward<A>(args)...); } ... }; this template class is defined in fiasco/src/types.h, what does the method 'construct' mean? i have tried to move this class to eclipse cdt project, but it can not be compiled correctly. how does this class be compiled in fiasco?
Hi, The new (_i) T(...) part is most likely a "placement new" ("most likely" because "new" can be overloaded but I don't think this is the case here). That is, it initializes an object of type T at the memory location given by the pointer _i, calling its constructor. The use of the ellipse declares ("typename... A") or unpacks ("A&&... args") a parameter pack. Read up on "variadic template parameters" if this is new to you. This means, "construct" can take any argument list that T has a constructor for. In short the cxx::forward allows the compiler to optimize argument passing. Read up on "perfect forwarding in C++". Why it may not have compiled in your eclipse project: Variadic templates (...) as well as r-value references (&& (in fact here && specifies universal references rather than r-value references)) are only available in C++ since c++11 so you might want to tell your compiler to use this standard (e.g. g++ -std=c++11). Hope this clarifies things a bit. Janis Am 08.05.2015 um 08:10 schrieb watermirror:
hi,
template< typename T > class Static_object { public: .... template< typename... A > T *construct(A&&... args) { return new (_i) T(cxx::forward<A>(args)...); } ... };
this template class is defined in fiasco/src/types.h, what does the method 'construct' mean? i have tried to move this class to eclipse cdt project, but it can not be compiled correctly. how does this class be compiled in fiasco?
_______________________________________________ l4-hackers mailing list l4-hackers@os.inf.tu-dresden.de http://os.inf.tu-dresden.de/mailman/listinfo/l4-hackers
participants (2)
-
Janis Danisevskis -
watermirror