- sizeof in a template, applied in a template type - 2 Updates
- "The Curious Case of the Longevity of C" - 2 Updates
- Need help on c++Linked list - 1 Update
- Awesome compile-time evaluation proposal - 1 Update
Richard Damon <Richard@Damon-Family.org>: Oct 07 04:53PM -0400 On 10/2/17 3:29 AM, David Brown wrote: > "new" and avoid the leaks in the first place. > C++ lets you use your own allocator with "new", and thus get the best of > both worlds. One thing worth pointing out, 'new' will do NOTHING to help with resource management. All new does is create object space from the heap, and then call the object constructor on it. Its advantage is that you can't forget to construct the object. Putting the pointer you get from new into a 'smart' object that will manage the lifetime is what help, and that starts with the automatic call of the destructor when the object goes out of scope. |
asetofsymbols@gmail.com: Oct 07 02:25PM -0700 No problem with malloc free in C++ object constructor destructor (at last for the compiler I use) What is the problem? The important I reserve enough memory for the object and that memory is good aligned Or I think it wrong? I already have a new/delete operator that use my malloc/ free implementation but I use always malloc/free, the same. |
"Mr. Man-wai Chang" <toylet.toylet@gmail.com>: Oct 07 09:00PM +0800 On 6/10/2017 8:24 AM, Lynn McGuire wrote: > to learn in these pre-Google 1 pre-StackOverflow/GitHub 2 days." > Yup, that is when I started looking at C. I bought TurboC in 1987 ??? > and I was in love. I bought Turbo C++ 3.0 back in 1992, I think. Couldn't quite remember! :) -- @~@ Remain silent! Drink, Blink, Stretch! Live long and prosper!! / v \ Simplicity is Beauty! /( _ )\ May the Force and farces be with you! ^ ^ (x86_64 Ubuntu 9.10) Linux 2.6.39.3 不借貸! 不詐騙! 不援交! 不打交! 不打劫! 不自殺! 請考慮綜援 (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa |
Vir Campestris <vir.campestris@invalid.invalid>: Oct 07 05:09PM +0100 On 06/10/2017 23:20, Richard wrote: > The closest I ever got to writing anything to do with editors was > playing around with TECO macros:). Teco? That takes me back! Did you ever type 0yy instead of 0tt? Andy |
asetofsymbols@gmail.com: Oct 07 02:38AM -0700 Possible there are many errors... #include <iostream.h> #include <stdlib.h> #include <time.h> #define u32 unsigned #define i32 int #define S sizeof #define R return #define F for #define MM malloc #define FF free #define ooo cout // Nodo generale rNode<T> di tipo T template<class T> class rNode{ public: T nd; // nd: valore del tipo conservato nel nodo u32 nrd; // nrd: valore associato alla lista a cui appartiene rNode* next; // puntatore al nodo successivo rNode* prec; // puntatore al nodo precedente }; //tList: Linked Lista doppia di rNode<T> di tipo T template<class T> class rList{ public: rNode<T>* pnd; // Punta al nodo iniziale per inserimento all'inizio u32 err; // err=1 allora l'obj e' in errore u32 rnd; // ogni lista ha il suo valore random per controllare meglio la rimozione o inserimento dopo nodo, di nodi u32 sz; // size in numero di nodi della lista static u32 t0; // srand(time(0)) has to be only 1 time; // at start is t0=0 when the first list is build: srand(time(0)), t0=1, any other list creation use only rand() // and not srand() //----------------------------- //--- costruttori e distruttori //lista **non inazializzata** e' in stato di errore err=1 //NB: **Qualsiasi operazione di assegnamento cambia lo stato della lista in err=0 [nessun errore]** rList(){u32 r;pnd=0;err=1;if(t0==0){r=time(0);srand(r);t0=1;}rnd=rand();sz=0;} rList(T* p,u32 s) {u32 i, r; rNode<T>*v,*w; if(t0==0){r=time(0);srand(r);t0=1;} pnd=0;err=1;rnd=rand();sz=0; if(p==0||s==0) if(s){ooo<<"\nArgomenti del costruttore non buoni\n"; R;} else R; if((int)s<0) {ooo<<"\nArgomenti del costruttore non buoni\n"; R;} F(i=0;i<s;++i) {if( (v=(rNode<T>*)MM(S(rNode<T>)))==0 ) {ooo<<"\nErrore memoria non sufficiente\n"; (*this).removeHead(0); R; } if(pnd==0){pnd=v;v->next=0;v->prec=0;} else {w=pnd;pnd=v; v->next =w; v->prec =w->prec?w->prec:w; w->prec =v; } v->nd =p[s-i-1]; // array pushed reverse i=0=>s-1 ok; i=s-1 =>s-i-1=s-s+1-1=0 ok v->nrd=rnd; ++sz; } err=0; } ~rList() {rNode<T>*p,*w; u32 led; F(led=err,p=pnd;p;p=w) {w=p->next;if(p->nrd==rnd){FF(p);--sz;}else led=1;} if(sz||(led&&pnd)) {ooo<<"\nErrore distruttore Lista="<<this<<"\n";} pnd=0;err=0;rnd=0;sz=0; } //--- funzione accesso array [per accedere all'elemento Lista[i] deve percorre i nodi della lista] //se indice fuori del range >=sz allora exit(1) T& operator[](i32 n) {rNode<T> *p,*w; i32 i; static T r; // the constructor of the type build r as error element for T if(err) R r; if(n<0||n>=sz){ooo<<"\nIndice Fuori range\n";R r;} // questo non invalida la lista, r e' l'elemento non inizializzato F(i=0,w=0,p=pnd;i<n&&p;++i,w=p,p=p->next); R p->nd; } //--- funzioni elemento void insertHead(T& e) {rNode<T>*v,*p; if(err&&pnd){ooo<<"\nInsert Non Riuscito\n"; R;} if( (v=(rNode<T>*)MM(S(rNode<T>)))==0 ) {err=1;ooo<<"\nInsert Non Riuscito\n";R;} if(pnd==0){pnd=v;err=0;v->next=0;v->prec=0;} else {p=pnd;pnd=v; v->next =p; v->prec =p->prec?p->prec:p; p->prec =v; } v->nrd=rnd; v->nd =e; ++sz; } //--- lista.removeHead(0) --rimuove ogni elemento della lista, err=1 non inizializata // lista.removeHead(&r) --salva in r l'elemento del nodo puntato da pnd // elimina tale nodo dalla lista int removeHead(T*r) {rNode<T>*p,*w; u32 led; if(r==0) // cancell the list if r==0, even if err=1 {F(led=err,p=pnd;p;p=w) {w=p->next;if(p->nrd==rnd){FF(p);--sz;}else led=1;} err=1; if(sz||(led&&pnd)) {pnd=0;sz=0;ooo<<"\nErrore distruttore Lista="<<this<<"\n";R 0;} pnd=0;sz=0; // rnd e' lasciato, err=1 perche' la lista non inizializzata R 1; } if(pnd==0||err)R 0; if(pnd->nrd!=rnd){err=1;R 0;} *r=pnd->nd; p=pnd->next; w=pnd->prec; if(p->nrd==rnd){FF(pnd);--sz;pnd=p;p->prec=w;} else {err=1;R 0;} if(pnd==0&&sz==0)err=1; //lista non inizializzata if(pnd!=0&&sz==0)err=1; // si e' accorto di un errore R !err; } //--- funzioni insert remove void insertTail(T& e) {rNode<T>*v,*p; if(err&&pnd){ooo<<"\nInsert Non Riuscito\n"; R;} if( (v=(rNode<T>*)MM(S(rNode<T>)))==0 ) {err=1;ooo<<"\nInsert Non Riuscito\n";R;} if(pnd==0){pnd=v;err=0;v->next=0;v->prec=0;} else {p=pnd->prec?pnd->prec:pnd; // solo un nodo pnd->v p=pnd // pnd->..->w->v p=w p->next=v; v->prec=p; v->next=0;pnd->prec=v; } v->nrd=rnd;v->nd=e; ++sz; } //--- lista.removeTail(0) --rimuove ogni elemento della lista, err=1 non inizializata // lista.removeTail(&r) --salva in r l'elemento del nodo puntato da pnd // elimina tale nodo dalla lista int removeTail(T*r) {rNode<T>*p,*w; if(r==0)R!err; if(pnd==0||err)R 0; //pnd->..->w->p p =pnd->prec?pnd->prec:pnd; if(p->nrd!=rnd){err=1;R 0;} w = p->prec; *r= p->nd; if(w){ w->next=0; pnd->prec=w; } FF(p);--sz; if(pnd==0&&sz==0)err=1; //lista non inizializzata if(pnd!=0&&sz==0)err=1; // si e' accorto di un errore R !err; } int insertAfter(rNode<T>*p, T& a) {rNode<T>*p,*v,*w; if((err!=0&&pnd!=0)||(p==0&&pnd!=0)||p->nrd!=rnd) {ooo<<"\nInsert Non Riuscito\n"; err=1; R 0;} if(p==0&&pnd==0) R (*this).insertHead(a); w=p->next; if(w==0) R (*this).insertTail(a); if( (v=(rNode<T>*)MM(S(rNode<T>)))==0 ) {err=1;ooo<<"\nInsert Non Riuscito\n"; R 0;} v->prec=p; v->next=w;p->next=v;w->prec=v; v->nrd =rnd;v->nd =a; ++sz; } void print(void) {rNode<T>*p; if(err){ooo<<"[List error]"; R;} ooo<<"["; F(p=pnd;p;) {ooo<<p->nd; if(p->nrd!=rnd){ooo<<"*"; err=1;} if(p=p->next)ooo<<", "; } ooo<<"] "; if(err)ooo<<"Trovato errore "; } void printRev(void) {rNode<T>*p; if(err){ooo<<"[List error]"; R;} ooo<<"["; if(pnd) for(p=pnd->prec;p;) {ooo<<p->nd; if(p->nrd!=rnd){ooo<<"*"; err=1;} if(p==pnd)break; ooo<<", "; p=p->prec; } ooo<<"] "; if(err)ooo<<"Trovato errore "; } int e(void){R err;} // Operatori friend // moltiplica due liste fino a che la size di entrambi lo permette friend T operator*(const rList& a, const rList& b) {static T r; //r should be initalizated to err object rNode<T>*pa,*pb; if(a.err||b.err)R r; F(r=0,pa=a.pnd,pb=b.pnd;pa&&pb;pa=pa->next,pb=pb->next) r+=(pa->nd)*(pb->nd); R r; } }; //fine classe rList<T> template<class T> u32 rList<T>::t0=0; // sembra che qui si genera lo spazio per l'obj t0 int mainx(void) {int i,r; rList<int> lista; for(i=0;i<10;++i) lista.insertTail(i); ooo<<"lista=";lista.print();ooo<<"\n"; ooo<<"lista=";lista.printRev();ooo<<"\n"; r=lista.removeTail(&i); ooo<<"i,r="<<i<<", "<<r<<"\n"; ooo<<"lista=";lista.print();ooo<<"\n"; ooo<<"lista=";lista.printRev();ooo<<"\n"; R 0; } int main(void) {int arr[]={0,0,7,0,5,0,0,8,0,4}, r; int ar1[]={0,0,0,5,6,0,0,0,0,5}; u32 i; rList<int> la(arr, S arr/S(int)); rList<int> l1(ar1, S ar1/S(int)); ooo<<"la=";la.print();ooo<<"\n"; ooo<<"l1=";l1.print();ooo<<"\n"; ooo<<"la=";la.printRev();ooo<<"\n"; r=la*l1; ooo<<"Result: la*lb="<<r<<"\n"; // try to use vector way [], that it is not O(1) as vector and array F(i=0,ooo<<"la=[";i<la.sz;++i) ooo<<la[i]<<" "; ooo<<"]\n"; R 0; } |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Oct 07 03:53AM +0200 On 10/6/2017 9:31 AM, Christian Gollwitzer wrote: >>> Hi, >>> I've just watched the recent talk from Herb Sutter: >>> https://www.youtube.com/watch?v=4AfRAVcThyA [snip] > There is a link on this youtube page to a github repo with the slides: > https://github.com/CppCon/CppCon2017/blob/master/Keynotes/Meta%20-%20Thoughts%20on%20Generative%20C%2B%2B/Meta%20-%20Thoughts%20on%20Generative%20C%2B%2B%20-%20Herb%20Sutter%20-%20CppCon%202017.pdf > I couldn't find a paper-like write-up for the talk. <url: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0707r0.pdf> My poor Thunderbird's inbox quickly filled up with comment notices after Herb posted the following, so I was able to find it quickly now :) : <url: https://herbsutter.com/2017/07/26/metaclasses-thoughts-on-generative-c/> Strangely, I haven't read it. I'm of the firm opinion that we need many things fixed before introducing even more language in the language, so to speak. E.g. I'd like const+non-const member function support, ideally integrated with support for covariant features (like used for e.g. a clone function, which now is redefined textually identically in every derived class). And modules of course. And real UTF-8 support, which involves a notion of detectable execution character set. Maybe at long last recognizing the reality of shared (dynamically loaded) libraries. There's lots that needs fixing, and committee's attention & time is very limited... Superbly better car information system, with built-in network radio & integration with emergency services, yep that's good. But wheels and carriage and engine most important IMHO. Cheers & hth., - Alf |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment