|
Unless I'm totally misreading it, could you do a map keyed on the character that's the process name and skip the set entirely?
|
# ? Oct 19, 2014 01:22 |
|
|
# ? Jun 7, 2024 17:24 |
|
Well hell, I forgot all about find_if! Thanks! fritz posted:Unless I'm totally misreading it, could you do a map keyed on the character that's the process name and skip the set entirely? This would be another approach. As I said before, I use anything other than vector so infrequently that I forget about them. I really need to get over that.
|
# ? Oct 19, 2014 01:26 |
|
hooah posted:Because when the client program wants to erase something, it'll ideally just give a char that is the process's name, and unless I'm misunderstanding it, set::find takes the same type as what the set stores. I suppose I could re-write the client program to create the Process objects itself, but I'd hoped to avoid having the client know about what seems like internal implementation details. C++14 introduces "transparent" comparators for ordered containers that allow you to do my_set.find('a'), but that might not be an option here. It'd work something like this: C++ code:
fritz posted:Unless I'm totally misreading it, could you do a map keyed on the character that's the process name and skip the set entirely? Yeah, this. Or std::array<std::unique_ptr<Process>, 1 << CHAR_BIT> my_set; considering the key set is so tiny. C++ code:
The Laplace Demon fucked around with this message at 01:34 on Oct 19, 2014 |
# ? Oct 19, 2014 01:30 |
|
The Laplace Demon posted:Or std::array<std::unique_ptr<Process>, 1 << CHAR_BIT> my_set; considering the key set is so tiny. Whoa whoa whoa, could you explain what the heck is going on here? I just glanced at what a std::array is (as opposed to a C array, I guess), and I understand what's going on until the << CHAR_BIT part. How can you insert anything into the literal 1?
|
# ? Oct 19, 2014 01:44 |
|
hooah posted:Whoa whoa whoa, could you explain what the heck is going on here? I just glanced at what a std::array is (as opposed to a C array, I guess), and I understand what's going on until the << CHAR_BIT part. How can you insert anything into the literal 1? It's a plain old left shift.
|
# ? Oct 19, 2014 01:47 |
|
hooah posted:How can you insert anything into the literal 1? STL devs thought they were smart and made << and >> both insertion operators and bitshifting operators at the same time, depending on what the object they're used on's implementation of them is. For numbers it's a bitshift, for iostream/stringstream it's a concat operation, and for filestream it's.. I guess technically concat but more insertion. STL's design decisions are Not Very Good.
|
# ? Oct 19, 2014 01:58 |
|
hooah posted:Whoa whoa whoa, could you explain what the heck is going on here? I just glanced at what a std::array is (as opposed to a C array, I guess), and I understand what's going on until the << CHAR_BIT part. How can you insert anything into the literal 1? Sorry. Basically this, but portable to platforms where a byte is not 8 bits and using std::array instead of raw arrays. C++ code:
|
# ? Oct 19, 2014 01:58 |
|
The Laplace Demon posted:Sorry. Basically this, but portable to platforms where a byte is not 8 bits I'm sure the three Cray computers left in the world will be happy for that consideration.
|
# ? Oct 19, 2014 02:04 |
|
Jewel posted:STL devs thought they were smart and made << and >> both insertion operators and bitshifting operators at the same time, depending on what the object they're used on's implementation of them is. For numbers it's a bitshift, for iostream/stringstream it's a concat operation, and for filestream it's.. I guess technically concat but more insertion. STL's design decisions are Not Very Good. Pretty sure iostream's clever overloading predates the STL.
|
# ? Oct 19, 2014 02:14 |
|
Suspicious Dish posted:I'm sure the three Cray computers left in the world will be happy for that consideration. Haha, right? This probably won't be running on DSPs where that'd ever be a concern nowadays, but I still use the constants for their documentation of intent.
|
# ? Oct 19, 2014 02:32 |
|
You're like that guy who does int buffer_size = width * height * sizeof (char);.
|
# ? Oct 19, 2014 02:38 |
|
Subjunctive posted:Pretty sure iostream's clever overloading predates the STL. Pretty sure the bit shift operators predate C++.
|
# ? Oct 19, 2014 02:40 |
|
pseudorandom name posted:Pretty sure the bit shift operators predate C++. Pretty sure that in this language family overloading doesn't. (You're pretty, I'm sure.) Edit: well, int/float/double/char overload of + was always there, I guess.
|
# ? Oct 19, 2014 03:02 |
|
Note to the guy with the sorted process list problem - the suggestion of a map keyed on the char-based process identifier would have to be in addition to the set, for your purposes, I think, since as I understand it the whole point of your ordered list was that you wanted the processes with adjacent memory to be listed adjacent to each other. If you just map on the names, you'll lose that ordering, but you could have a set of the addresses and a map of char-based identifier to addresses and have fun trying to keep them in sync. Unless some balance-combination of [the number of entries is large and you're doing char-based lookups frequently], you're likely better off just doing a linear search through your set for the char-based key. The C++14 transparent thing for that is cool, but if you don't have C++14 available then writing your own 'find' function for finding on a different criterion is really okay. (You could use std::find_if to skip writing the loop part.)
|
# ? Oct 19, 2014 03:24 |
|
Jewel posted:STL devs thought they were smart and made << and >> both insertion operators and bitshifting operators at the same time, depending on what the object they're used on's implementation of them is. For numbers it's a bitshift, for iostream/stringstream it's a concat operation, and for filestream it's.. I guess technically concat but more insertion. STL's design decisions are Not Very Good. iostreams is an entirely separate library from the STL. It's also the oldest of the various libraries added to the C++ standard library (not counting the C stdlib), and it shows.
|
# ? Oct 19, 2014 03:58 |
|
Suspicious Dish posted:You're like that guy who does int buffer_size = width * height * sizeof (char);.
|
# ? Oct 19, 2014 05:16 |
|
Suspicious Dish posted:You're like that guy who does int buffer_size = width * height * sizeof (char);. That's actually valuable; it makes it immediately obvious to the reader that this is a byte-size calculation and that it's for an array of chars.
|
# ? Oct 19, 2014 06:25 |
|
Suspicious Dish posted:You're like that guy who does int buffer_size = width * height * sizeof (char);. It's future-proofing! Maybe they'll change sizeof(char) at some point! I do this because it makes my code ever-so-slightly clearer
|
# ? Oct 19, 2014 12:22 |
|
Jewel posted:STL devs thought they were smart and made << and >> both insertion operators and bitshifting operators at the same time, depending on what the object they're used on's implementation of them is. For numbers it's a bitshift, for iostream/stringstream it's a concat operation, and for filestream it's.. I guess technically concat but more insertion. STL's design decisions are Not Very Good. iostreams are pre-STL. Thank Bjarne for that poo poo; STL was a much needed improvement on prior C++ libraries.
|
# ? Oct 19, 2014 13:12 |
|
Is there a standard alternative to iostreams that isn't as weird? Or a chance there ever will be one in a future c++ spec?
|
# ? Oct 19, 2014 13:32 |
|
Heavy_D posted:Is there a standard alternative to iostreams that isn't as weird? Or a chance there ever will be one in a future c++ spec? There really isn't a great alternative. Realistically, you'd probably use something else to do user input in more than a toy project, and if you have to do a lot of dumb string stuff or worry about i18n you might just be using the wrong tool for whatever you're trying to do.
|
# ? Oct 19, 2014 13:58 |
|
Heavy_D posted:Is there a standard alternative to iostreams that isn't as weird? Or a chance there ever will be one in a future c++ spec? stdio.h gives up type safety but is less painful to use in most cases imo. There have been a couple of attempts from academia to make a better C++ IO library but none have caught on.
|
# ? Oct 19, 2014 16:55 |
|
Technically, you could get a typesafe stdio now that variadic templates exist. The odds of that happening (at least in a standard way) are pretty slim however.
|
# ? Oct 19, 2014 17:40 |
Could C++14 constexpr functions together with static_assert be used to type-check arguments for printf-style format strings?
|
|
# ? Oct 19, 2014 18:22 |
|
GCC already gives you warnings for arguments that conflict with the types in printf format strings, no idea what the implementation is based on (probably a bunch of builtin crap)
|
# ? Oct 19, 2014 19:02 |
|
Blotto Skorzany posted:GCC already gives you warnings for arguments that conflict with the types in printf format strings, no idea what the implementation is based on (probably a bunch of builtin crap) Hooray for dependent types
|
# ? Oct 19, 2014 19:13 |
|
Is the problem with iostreams vs stdio really just that overloading << is gross and not the more architectural poo poo?
|
# ? Oct 19, 2014 19:13 |
|
q: when you feed a boolean into a stream, does it print a numeric or textual representation? a: who knows!
|
# ? Oct 19, 2014 19:49 |
|
FamDav posted:q: when you feed a boolean into a stream, does it print a numeric or textual representation? Surely it prints 0 or 1 unless you specify boolalpha, yes?
|
# ? Oct 19, 2014 19:54 |
|
hooah posted:Surely it prints 0 or 1 unless you specify boolalpha, yes? This is correct. C++ code:
code:
|
# ? Oct 19, 2014 20:00 |
|
The who knows is because every time you pass configuration to the stream, you have now potentially changed the output of any other log statement at any other point in your system, unless they have also defensively set their configuration.
|
# ? Oct 19, 2014 20:05 |
|
That's why you use some boost utility thing that saves the iostream state and restores it on scope exit!
|
# ? Oct 19, 2014 21:54 |
|
Vanadium posted:That's why you use some boost utility thing that saves the iostream state and restores it on scope exit! Yeah, I'm going to just manually push my state onto a stack at the start of a routine and pop it back off at the end like an
|
# ? Oct 19, 2014 22:14 |
|
Blotto Skorzany posted:Yeah, I'm going to just manually push my state onto a stack at the start of a routine and pop it back off at the end like an
|
# ? Oct 19, 2014 22:23 |
|
Vanadium posted:Is the problem with iostreams vs stdio really just that overloading << is gross and not the more architectural poo poo? I will mess up your program by doing cout << hex. It's just a horrible, state-ful API and that's not really what you want. Something basically like printf that was typesafe and also called the correct cast operator for a thing when giving it weird data would basically be the best printf replacement. Otherwise, printf and doing the cast manually is better than iostream.
|
# ? Oct 19, 2014 22:44 |
|
Suspicious Dish posted:I will mess up your program by doing cout << hex. It's just a horrible, state-ful API and that's not really what you want. Boost.Format does exist. I used for a little bit and didn't want to kill myself (any more than working with C++ in general does).
|
# ? Oct 19, 2014 22:52 |
|
I'm trying to reduce my programs memory usage and so far it's going badly. I have a std::vector of Vector3D(double x,y,z) that I want to convert to a std::vector of pointers to these Vector3Ds as I'm going to copy these a shitload of times in a recursive algorithm.code:
|
# ? Oct 19, 2014 22:55 |
|
Boz0r posted:I'm trying to reduce my programs memory usage and so far it's going badly. You're using C++.
|
# ? Oct 19, 2014 23:13 |
|
Boz0r posted:I'm trying to reduce my programs memory usage and so far it's going badly. I have a std::vector of Vector3D(double x,y,z) that I want to convert to a std::vector of pointers to these Vector3Ds as I'm going to copy these a shitload of times in a recursive algorithm. Do you have some reason to be using shared_ptrs, as opposed to unique_ptrs, or even bare pointers?
|
# ? Oct 19, 2014 23:16 |
|
|
# ? Jun 7, 2024 17:24 |
|
code:
Suspicious Dish posted:You're using C++. Congrats on your recent poo poo post. seiken fucked around with this message at 23:21 on Oct 19, 2014 |
# ? Oct 19, 2014 23:18 |