/robowaifu/ - DIY Robot Wives

Advancing robotics to a point where anime catgrill meidos in tiny miniskirts are a reality.

Downtime was caused by the hosting service's network going down. Should be OK now.

An issue with the Webring addon was causing Lynxchan to intermittently crash. The issue has been fixed.

Max message length: 6144

Drag files to upload or
click here to select them

Maximum 5 files / Maximum size: 20.00 MB

More

(used to delete files and postings)


Vera stayed by Anon's side, continuing to support him in building new programs, but their primary goal was no longer work or money or fame.


C++ Learning Classroom Chobitsu Board owner 02/11/2023 (Sat) 02:56:07 No.19777
Keep your eyes on the prize edition • v231125 week-thirteen, lecture: semester-end catchup (N/A) - this week's reading assignments: N/A - reading review: N/A - reading preview: PPP2 ch12 - this week's assignments: (N/A) --- So, we're done with the STL semester, this is just a decompress week to wrap up any questions you might have left/turn in your work catchup. We'll take a break until sometime in the new year, where we'll pick back up with creating C++ GUIs using the FLTK library. Merry Christmas season Anons, please enjoy the break. --- • Our classroom's textbook thread is here : (>>18749) - you'll find a link in that OP to an archive of all the code examples therein, for your local study • This course material is primarily derived from Bjarne Stroustrup's college freshman textbook Programming -- Principles and Practice Using C++, 2e (aka, PPP2) https://www.stroustrup.com/programming.html - please obtain a copy of that book for yourself, as you'll need it to complete this course successfully --- >note: if you see the thread pinned, it (should) mean we're nearby to help, so ask away! --- • BTW, we'd like to get some feedback from the class participants about this C++ programming class. Specifically, I have a few questions and I seek ideas & advice from Anons how to approach these needs: - How to best run our classroom using (only) this IB? - How to give out exercises & assignments, & receive solutions? - How to assign grades? - How to manage the asynchronous nature of IB communications, student-to-instructor (and vice versa)? - How to utilize the textbook thread well, since it (mostly) contains already-worked solutions? - How to do tests? - How to manage a final group project together? What should that project be in fact? - Any other adivce or suggestions you think would be helpful. Please post your recommendations for these topics ITT Anon, thanks! :^) --- >unless otherwise-noted, everything ITT is MIT (Expat) licensed >copyright 2023
Edited last time by Chobitsu on 11/25/2023 (Sat) 10:22:14.
Edited last time by Chobitsu on 11/04/2023 (Sat) 16:22:44.
Edited last time by Chobitsu on 11/04/2023 (Sat) 16:22:58.
Edited last time by Chobitsu on 11/04/2023 (Sat) 16:23:10.
>>26196 Lecture 09 ends 9
>spare reserve
>spare reserve
>spare reserve
how do you make a vector with function pointers? im trying to make a callstack
>>26201 trying to do vector<int *(int, ...)>func(5) but it prints an entire page of garbage as an error message cant even read any of, with an array its fine though int (*func[5])( int, ... )
>>26201 >>26204 >im trying to make a callstack Neat! I'm not on a box I can do a quick check for you, but it seems to me this should probably work: vector<int (*)(int, ...)> func(5) I'll take a look at it sometime tomorrow when I'm better able to. BTW, since you're using C++ you can probably take advantage of that and go all the way to creating a full class for your Callstack with all the bells & whistles neatly packaged up?
>>26206 I'm not into C++, so I can't help you directly. But if you would use the Opera browser for your project, then you could use chatGPT (3) in the sidebar the whole time. I'm having positive experiences with it, asking about Python, libraries, examples, Emacs shortcuts, fixing some code, making it shorter ... As I said, not C++ but Python, though it might work for C++ as well. With an account on sites like Poe.com you can also ask bigger models on their site.
>>26201 >how do you make a vector with function pointers? Here's a quick example using C++11 lambdas, Anon. Hopefully this will get you kickstarted : >callstack_main.cpp // build & run : // g++ callstack_main.cpp -std=c++14 && ./a.out #include <functional> #include <iostream> #include <vector> using namespace std; // a couple of arbitrary void functions : void prt_num(int i) { cout << i << '\n'; } void prt_dbl_num(int i) { cout << (i * 2) << '\n'; } int main() { // an empty vector of void functional types vector<function<void()>> funcs; // store a few lambdas (aka, 'closures') into the container : funcs.push_back([]() { prt_num(42); }); funcs.push_back([]() { prt_num(700); }); funcs.push_back([]() { prt_num(9'001); }); funcs.push_back([]() { prt_dbl_num(42); }); funcs.push_back([]() { prt_dbl_num(700); }); funcs.push_back([]() { prt_dbl_num(9'001); }); // execute all stored functionals, beginning to end for (auto const& fn : funcs) fn(); } >output: 42 700 9001 84 1400 18002 Try that (adapting it to your specific usecase ofc), then let me know how it goes please. Cheers. :^) >>26211 Thanks NoidoDev! That's good advice, and much appreciated. Cheers. :^) >=== -edit code example
Edited last time by Chobitsu on 11/05/2023 (Sun) 15:57:55.
>>26215 nice thats what i needed, ty
>>26221 Great. Please post results when you've perfected everything Anon. BTW, now you're rolling with things, I'd suggest you investigate std::stack[1]. I believe you'll find all the semantics you want all there for you in a purpose-designed C++ container. Cheers. :^) 1. https://en.cppreference.com/w/cpp/container/stack
>>26222 thanks was just playing around and made a simple regex engine, the ugliness is unavoidable i think#include <functional> #include <iostream> #include <vector> #include <cstring> using namespace std; class regex { public: struct { const char *ptr; int cur, len; }Text; struct { int cur, len; }Match; const char *expr; int cur; vector<function<int()>> funcs; void reset( void ) { Text.cur = 0; } int mChar( const char c ) { return ( Text.ptr[ Text.cur ] == c ); }; int mAny( void ) { char c = Text.ptr[ Text.cur ]; return ( c != '\n' ) & ( c != '\0' ); }; int mOpt( void ) { int m = funcs[ ++cur ](); Text.cur -= !m; return m + !m; } int mMulti( class regex *Left, class regex *Right, int greedy ) { int m; int save = Left->Text.cur; Right->Text.len = 1; do { m = Left->funcs[ Left->funcs.size() -2](); Left->Text.cur += m; Right->Text.len += m; } while ( m ); Left->Text.cur = save; Right->Text.ptr = &Left->Text.ptr[ Left->Text.cur ]; Right->Text.cur = 0; Right->exec(); int ret = Right->Match.cur + Right->Match.len ; if ( greedy ) do { ret = Right->Match.cur + Right->Match.len ; m = Right->exec(); } while ( m ); return ret; } int exec( void ) { if ( Text.cur >= Text.len ) return 0; for ( cur=0; cur<funcs.size(); cur++ ) { int m = funcs[ cur ](); if ( m ) { Text.cur += m; continue; } cur = -1; Text.cur = Match.cur + 1; Match.cur = Text.cur; if ( Text.cur >= Text.len ) break; } Match.len = Text.cur - Match.cur ; return Match.len; }; void bind( const char *text, int len ) { Text.ptr = text; Text.len = len; Text.cur = 0; } void compile( const char *expr ) { funcs.clear(); this->expr = expr; int len = strlen( expr ); for ( int i=0; i<len; i++ ) switch ( expr[i] ) { case '\\': // escape ++i; default: // char funcs.push_back([this,expr,i]() { return mChar( expr[i] ); } ); break; case '.': // any funcs.push_back([this]() { return mAny(); } ); break; case '?': // zero or one if ( !i ) break; case '*': // zero or more funcs.push_back( funcs.back() ); funcs[ funcs.size() -2 ] = [this]() { return mOpt(); } ; if ( expr[i] == '?' ) break; case '+': // one or more class regex *Right = (class regex *)calloc( sizeof(class regex), 1 ); Right->compile( &expr[i+1] ); funcs.push_back ( [this,Right,expr,i]() { return mMulti( this, Right, ( expr[i+1] != '?' ) ); } ); return; } }; }; int main() { class regex Expr1 = {}; Expr1.compile( "t5?.+?st\\?.x+ s.*enX*d" ); Expr1.bind( "afsd test?xxx sqwe enp end? @@", 12 ); int m = Expr1.exec(); printf( "\033[1;7;93m str = '%s' \n\033[0m" "\033[1;7;96m expr = '%s' \n\033[0m" "\033[1;7;92m pos=%d len=%d \n match = '%.*s' \n\033[0m", Expr1.Text.ptr, Expr1.expr, Expr1.Match.cur, m, m, &Expr1.Text.ptr[Expr1.Match.cur] ) ; }
>>26231 Wow very nice stuff Anon! Some clever things going on there. Also, very cool to me personally seeing you embracing the benefits of C++ . I too trod a path of C first, then C++. They are definitely different ways of thinking about & doing things, but IMO the further along you get in the journey towards mastery of C++, the more you wind up mostly :^) appreciating much the language has to offer. >tl;dr Eventually this language becomes rather fun to use (explicitly one of Bjarne's major stated goals) and the power of free abstractions simply can't be beat! or ignored, IMO. :^)
Lecture 10 begins 1
>>26325 Lecture 10 ends 9
>spare reserve
>spare reserve
>spare reserve
Open file (80.73 KB 1079x791 virginityiscool.jpg)
>>26326 My C++ teacher docs points on my assignments when I add lying berries to my programs but don't use them. Like if i had <fstream> but didn't have any files read in the program. I just copy and paste from a large list and then slap it in my program. I wish he didn't do that but oh well. As a programmer, is it bad programming practice to add certain lying berries to your program if you don't use them? like adding <string> to your program but not having any strings?
>>26365 >As a programmer, is it bad programming practice to add certain lying berries to your program if you don't use them? like adding <string> to your program but not having any strings? Please define 'lying berries' for me a bit clearer, Anon. As to adding superfluous #includes, it simply adds slightly to the compilation process workload (by expanding the entire text of the string library and all it's dependencies in-place as a preprocessing step). Otherwise it has no effect on the compiled binary in either size or runtime. OTOH, it's certainly considered bad form to do so, as well as adding anything unnecessary to the code in the file you're working on. At the small scale you're likely to encounter as a student, these are relatively trivial concerns. Once you're coding professionally, you may be working on 1M+ line codebases (such as a robowaifu's), and such faux pas can be a real nuisance. Best to take your instructor's advice in this specific matter Anon. He's just trying to prepare for the real world in this case.
Open file (15.24 KB 292x268 terrydavissmile.jpeg)
>>26366 >Please define 'lying berries' for me a bit clearer, Anon. Sorry, I was just joking around. libraries sounds kind of like "Lying berries" so I thought it was funny. Thanks for clearing that up for me, I just wanted to know if he was right and it turns out it is. Another reason I wanted to do that is because It's sort of like a signature of mine. Like "oh hey look at all these extra libraries added on , this is definitely anon's work. " One of my biggest fears with my programming classes is to get accused of using AI. I know it happened at a university in Texas recently.
>>26369 >Thanks for clearing that up for me Nprb, I'm glad you're asking about such things since it helps clear up misconceptions in the beginner's minds (this is a classroom thread after all heh). For example, most students think that the compiler is somehow involved with the runtime operation of their programs. It isn't. The binary runs without any compiler interaction at all. Stuff like that. >One of my biggest fears with my programming classes is to get accused of using AI. I know it happened at a university in Texas recently. Honestly, that's their problem IMO, not yours. Just find a consistent naming/commenting/formatting style (please use clang-format, kthx) and that should go a long way for you while you're a student. >also, > based schizo pic saved. :^)
Open file (15.36 KB 576x294 2023-11-13_10-48-26.png)
Open file (15.92 KB 591x304 2023-11-13_10-49-09.png)
>>26365 >>26366 One other thing I might add; the reference sites will tell you about which libraries are needed, for which standard C++ facilities you need. For example, here's vector:[1] > #1 and map:[2] > #2 1. https://en.cppreference.com/w/cpp/container/vector 2. https://en.cppreference.com/w/cpp/container/map
>>26392 why arent there just man pages for c++ like with libc
>>26394 nvm saw theres a libstdc++-10-doc package its just not installed by default
>>26394 >why arent there just man pages for c++ like with libc Yeah, it's an issue. Here's a hack: https://github.com/jeaye/stdman
Lecture 11 begins 1
>>26485 This completes our second phase of the class. That's it for this year, Anons! See you in the new year where we'll pick up with PPP2 ch12 & GUIs. :^) Lecture 11 ends 8
>spare reserve
>spare reserve
>spare reserve

Report/Delete/Moderation Forms
Delete
Report