[Erledigt] template fehler?
-
brotbernd schrieb:
darkfate schrieb:
Die Funktionen get_xxxx_by_pos(x) nutze ich beim laden/speichern einer Projektdatei und bei der opengl Ausgabe in einer for Schleife.
Also da Laden und Speichern ist wurst, das ist eh langsam. Aber für Grafikausgabe klingt das ganz schlimm. Ist denn deine for schleife von pos=0 bis x ?
Dann iteriere doch einfach ganz normal durch die map.ja von pos=0 bis x. Ist aber nicht weiter wild.
Funktioniert eigentlich ganz gut.Ich möchte diese Topologie Klasse geschlossen von der Applikation halten und nur externe Methoden anbieten über die man sie ansprechen kann. Am besten so einfach wie möglich, daher das get_xxx_by_xxx(x)
-
darkfate schrieb:
ja von pos=0 bis x.
Von vorne bis hinten durch ist ja kein random access. Dafür musst du ja nicht für jede Position wieder von vorne anfangen zu zählen (
std::advance(it,pos))class Geotopology{ public: typedef std::map<pano_uint, Utm> coord_map; typedef coord_map::const_iterator coord_iter; typedef std::map<pano_uint, Knot> knots_map; typedef coord_map::const_iterator knots_iter; coord_iter first_coord() const; coord_iter last_coord() const; knots_iter first_knot() const; knots_iter last_knot() const; private: coord_map coords; knots_map knots; }; int main() { using namespace std; Geotopology g; for(Geotopology::knots_iter it = g.first_knot(),end = g.last_knot(); it != end; ++it) { glDraw(*it); } // std::for_each(g.first_knot(), g.last_knot(), ...); return 0; }
-
brotbernd schrieb:
darkfate schrieb:
ja von pos=0 bis x.
Von vorne bis hinten durch ist ja kein random access. Dafür musst du ja nicht für jede Position wieder von vorne anfangen zu zählen (
std::advance(it,pos))class Geotopology{ public: typedef std::map<pano_uint, Utm> coord_map; typedef coord_map::const_iterator coord_iter; typedef std::map<pano_uint, Knot> knots_map; typedef coord_map::const_iterator knots_iter; coord_iter first_coord() const; coord_iter last_coord() const; knots_iter first_knot() const; knots_iter last_knot() const; private: coord_map coords; knots_map knots; }; int main() { using namespace std; Geotopology g; for(Geotopology::knots_iter it = g.first_knot(),end = g.last_knot(); it != end; ++it) { glDraw(*it); } // std::for_each(g.first_knot(), g.last_knot(), ...); return 0; }Sieht ganz interessant aus. Danke.
-
Naja an manchen Stellen kann ich auf diese get_xxx_by pos nicht verzichten.
Ich habe noch get_coord_id_by_pos, get_knot_id_by_pos, ...
Das ist für mich ein sehr bequemer aufbau da ich zu einer passenden
Position die id zurückbekomme..
-
darkfate schrieb:
Meine Vorgaben sind:
Koordinaten, Knoten, Kanten, Maschen: unique id, nach id sortiert;ämmm... kannst du als id nicht einfach die Position in einem
vectornehmen?
Die ist eindeutig und sortiert. Diese ganzen maps kommen mir sowieso grad seltsam vor.
Wieso ist das nicht sotemplate<typename T> struct coord { T x, y, z; }; template<typename T> struct knot { typedef coord<T> coord_type; coord_type location; }; template<typename T> struct edge { typedef knot<T> knot_type; knot_type from, to; }; template<typename T> struct face { typedef edge<T> edge_type; std::vector<egde> edges; };
-
brotbernd schrieb:
ämmm... kannst du als id nicht einfach die Position in einem
vectornehmen?
Die ist eindeutig und sortiert. Diese ganzen maps kommen mir sowieso grad seltsam vor.Position als id ist keine gute Idee.
Eine id darf nicht nach einem Löschvorgang noch existieren.
-
Entschuldigt dass ich euch so foltere aber irgendwie scheinen templates nicht meine Stärke zu sein und die Kompilierfehler sind noch kryptischer.
fwd_type soll den benötigten Typ weiterleiten.
#include <map> using namespace std; class Utm{ }; class Knot{ }; template<typename> struct fwd_type{ }; template<> struct fwd_type<std::map<int, Utm>> { typedef Utm class_type; }; template<> struct fwd_type<std::map<int, Knot>> { typedef Knot class_type; }; template<typename T> struct topology{ typedef typename fwd_type<T>::class_type type_t; typedef pair<int,type_t> pair; typedef map<int,type_t>::iterator it; typedef map<int,type_t>::const_iterator const_it; typedef std::pair<it,bool> bool_it; }; class Geotopology{ private: template<typename T, typename S> int get_id_by_pos(T& container, S pos) const; map<int, Utm> coords; map<int, Knot> knots; public: int get_coord_by_pos(int pos_in_map) const; int get_knot_by_pos(int pos_in_map) const; }; template<typename T, typename S> int Geotopology::get_id_by_pos(T& container, S pos) const{ typedef typename topology<T>::const_it const_iter_t; const_iter_t i = container.begin(); std::advance(i, pos-1); return i->first; } int Geotopology::get_coord_by_pos(int pos_in_map) const{ return get_id_by_pos(coords,pos_in_map); } int main(void){ return 0; }Als Compileroutput kommt:
1>(16): error C2327: 'topology<T>::type_t' : is not a type name, static, or enumerator 1>(21) : see reference to class template instantiation 'topology<T>' being compiled 1>(16): error C2065: 'type_t' : undeclared identifier 1>(17): error C2327: 'topology<T>::type_t' : is not a type name, static, or enumerator 1>(17): error C2065: 'type_t' : undeclared identifier 1>(17): warning C4346: 'std::map<_Kty,_Ty,_Pr,_Alloc>::iterator' : dependent name is not a type 1> prefix with 'typename' to indicate a type 1>(17): error C2146: syntax error : missing ';' before identifier 'it' 1>(17): error C2838: 'iterator' : illegal qualified name in member declaration 1>(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>(18): error C2327: 'topology<T>::type_t' : is not a type name, static, or enumerator 1>(18): error C2065: 'type_t' : undeclared identifier 1>(19): error C2065: 'it' : undeclared identifierWarum bekomme ich den richtigen Typ nicht weitergeleitet, es kann doch nicht so schwer sein. Woraus soll ich im Compileroutput schauen?
-
typename fwd_type<T>::class_type type_t;da fehlt nen typedef

bb
-
unskilled schrieb:
typename fwd_type<T>::class_type type_t;da fehlt nen typedef

bb
Danke, das war wohl der erste von mehreren Fehlerserien

1>(17): warning C4346: 'std::map<int,fwd_type<<unnamed-symbol>>::class_type>::iterator' : dependent name is not a type 1> prefix with 'typename' to indicate a type 1>(21) : see reference to class template instantiation 'topology<T>' being compiled 1>(17): error C2146: syntax error : missing ';' before identifier 'it' 1>(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>(18): warning C4346: 'std::map<int,fwd_type<<unnamed-symbol>>::class_type>::const_iterator' : dependent name is not a type 1> prefix with 'typename' to indicate a type 1>(18): error C2146: syntax error : missing ';' before identifier 'const_it' 1>(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>(19): error C2065: 'it' : undeclared identifier
-
Man... ich habe das
constintemplate<typename T, typename S> int Geotopology::get_id_by_pos(T& container, S pos) constübersehen.
Natürlich gehört in fwd_type auch das
constzurstd::map<>template<> struct fwd_type<const std::map<int, Utm>> { typedef Utm class_type; }; template<> struct fwd_type<const std::map<int, Knot>> { typedef Knot class_type; };Danke unskilled du hast mich vor der Verzweiflung bewahrt.