|
Really beginner question here, are these the same?C++ code:
C++ code:
I guess a related question is, to clear a string value, can I safely set s = ""; or should I be doing s.clear();? Edit: When googling, I see a lot of discussion surrounding "copy constructor vs assignment operator" but I don't think that's what I'm looking for. epswing fucked around with this message at 18:55 on Apr 17, 2019 |
# ? Apr 17, 2019 18:40 |
|
|
# ? Jun 8, 2024 14:24 |
They are completely identical. The assign() function also lets you do substring extraction, assigning from raw character arrays, and more, but for straight assignment from one std::string to another there is zero difference.
|
|
# ? Apr 17, 2019 19:02 |
|
nielsm posted:They are completely identical. Great, thanks!
|
# ? Apr 17, 2019 20:22 |
|
epalm posted:I guess a related question is, to clear a string value, can I safely set s = ""; or should I be doing s.clear();? These are pedantically slightly different. s.clear(); Changes the size member of the string to 0 and maybe frees some storage s = ""; Does everything s.clear() did, then copies from an array of char's until it reaches a 0x00 byte. That will happen immediately since the right hand side is an empty string. In the 2nd one, there may be a length 1 constant global char array in memory somewhere depending on how your compiler implements/optimizes it. The first one never has that.
|
# ? Apr 18, 2019 04:13 |
|
I have another small thing which I just can't seem to figure out. In my header file, I have the following... code:
code:
code:
|
# ? Apr 19, 2019 17:20 |
|
Yeah, you are gonna have to provide more code to show what you are trying to do, and what the error is.
|
# ? Apr 19, 2019 17:25 |
Your operator== should generally be const, and take a const reference to the other object as parameter. But definitely provide some more specifics and more error messages.
|
|
# ? Apr 19, 2019 17:30 |
|
Xarn posted:Yeah, you are gonna have to provide more code to show what you are trying to do, and what the error is.
|
# ? Apr 19, 2019 17:31 |
|
Kuule hain nussivan posted:Just let me know what you need and I'll try and post it. I'm still very new to C++ so I don't really have a good idea of what's relevant to the issue. 1) The code 2) The error message. If there are a zillion error messages, the first is the most relevant.
|
# ? Apr 19, 2019 17:32 |
|
edit: nevermind
Dren fucked around with this message at 17:47 on Apr 19, 2019 |
# ? Apr 19, 2019 17:41 |
|
I think this is all the relevant stuff from .hh file.code:
code:
code:
|
# ? Apr 19, 2019 17:43 |
|
Kuule hain nussivan posted:I think this is all the relevant stuff from .hh file. I think it is because your == operator isn't const so it isn't finding it From the error message: quote:In instantiation of 'constexpr bool std::equal_to<_Tp>::operator()(const _Tp&, const _Tp&) const Jose Valasquez fucked around with this message at 18:15 on Apr 19, 2019 |
# ? Apr 19, 2019 17:47 |
|
try this:code:
|
# ? Apr 19, 2019 17:50 |
|
Dren posted:try this: This did it! Thank you very much! What is the magic behind the 'friend' keyword? Without it, my IDE complains that I'm giving the operator 3 parameters, which I've understood is caused by an implied this-parameter.
|
# ? Apr 19, 2019 18:45 |
|
Using friend is the only way to declare non-member functions inside a class. In this case, friend has nothing to do with access.
|
# ? Apr 19, 2019 19:15 |
|
I declare it with the friend keyword because of core guidelines rule C.161: Use nonmember functions for symmetric operators http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c161-use-nonmember-functions-for-symmetric-operators I wasn't sure the syntax for declaring a free function in the outer class's namespace or if it's even allowed, so I declared it friend inside the struct. You had another problem which was that the argument to operator== wasn't const reference. I think that was the only thing stopping you from compiling.
|
# ? Apr 19, 2019 21:25 |
|
Kuule hain nussivan posted:
Just want to point out one thing: the syntax for const member functions has the const after the argument list. As written here, it is still not a const member function, it merely returns a const bool. You need to write: code:
|
# ? Apr 19, 2019 22:03 |
|
Is it possible to create a specialized version of this function to use when OutChannels is 1? I'm not sure it is even possible.. I have no idea what the syntax would be if it were possible.code:
baby puzzle fucked around with this message at 16:35 on Apr 22, 2019 |
# ? Apr 22, 2019 16:24 |
|
Just overload it. Function template specialization partial ordering should pick the more specialized candidate. You can static_assert in the other candidate if you're worried about it.
|
# ? Apr 22, 2019 22:48 |
|
Not strictly a c++ question here but a question about c++ projects with visual studio, I didn't see a better thread to post this in. I recently moved a project I am working on from VS 2015 to 2017. When I brought it into 2017 I re-targeted it to use the new v141 toolset. Despite this, my project still has "(Visual Studio 2015)" appended to it's name in the solution explorer. As far as I can tell this project is actually building with the new 2017 compiler, I'm just unsure of why it is still marked as a 2015 project. The project properties windows shows the toolset as v141. This isn't actually causing me any problems and everything is working how I expect, I'm just not sure what the (Visual Studio 2015) designation means or if it is having any meaningful impact on my project. Anyone know what is up with this?
|
# ? Apr 23, 2019 15:31 |
|
Rahu posted:Not strictly a c++ question here but a question about c++ projects with visual studio, I didn't see a better thread to post this in. Did you change toolset for all build configurations? I think it will still show that "(Visual Studio 2015)" if even one of the build configurations uses the old toolset.
|
# ? Apr 23, 2019 17:58 |
|
Ah, that was sort of it. I had changed all of my build configurations to use v141, but I was referencing a .props file that still was setting v140 as the default toolset. Even though every build configuration was overriding that to v141, it still made the (Visual Studio 2015) come up. Thanks
|
# ? Apr 24, 2019 02:55 |
|
Any ASIO experts know a prettier way to write AsyncReadOneByte()? I feel like the effort involved in order to just adapt a completion handler to accept/return stuff is pretty annoying. Is there a way to replace the struct with like boost::asio::bind_executor() and a lambda? I copy pasted the documentation's about executor_type / get_executor(). I don't understand why it is 'essential for correctness to preserve the executor of the user-supplied completion handler.' Is there a good doc or video about this? code:
|
# ? Apr 29, 2019 15:04 |
|
Looks like boost 1.70 added a slightly nicer way to set up composed operations. It's still not pretty, but less noisy than before, and I think it does the 'correct' thing w/r/t executors. Extremely c++14+ only though.code:
|
# ? Apr 30, 2019 17:30 |
|
What's the goal beyond boost::asio::async_read(s, boost::asio::buffer(data, 1u), handler);? I'm getting owned everyday trying to get HTTPS health checks from AWS ELB working with ASIO and Beast. The docs are rear end for both Boost and AWS. 1) Health check is failing and killing my ECS instances. What precisely is the failure is actually not noted. It may be a non-200 code or a failure to connect and read within a time limit. I can tell from logs when my app should be reporting success though. It can take a while to startup, and can get killed before it is in a ready state. 2) In pretty much default setup I run out of memory due to the server-side caching of OpenSSL's session cache with a default limit of 20,000 sessions that apparently means many GBs. 3) TLS session tickets are enabled by default and AWS doesn't appear to care. 4) AWS has a requirement on ciphers and SSL/TLS levels, you can configure on the frontend but is locked on the backend. 5) Whatever you setup in OpenSSL appears to be completely ignored by the openssl CLI but can be picked up in other tools as long as they don't crash out completely, i.e. sslscan. 6) ASIO SSL Context options are retarded. Apparently compression is disabled by default and there is an option to disable compression. However AWS ELB appears to want compression as SSL handshake raises an error if you explicitly disable compression. 7) There is a default_workarounds set of options for like SSLv1/v2 days that everyone still uses in examples and code. Skip that poo poo already, no one uses MSIE 3 or whatever any more. 8) You can set the SSL Context to be tlsv12_server yet still connect with TLSv1.0 or v1.1, this is messed up. 9) RHEL OpenSSL disables all elliptical ciphers by default or something like that and those ciphers with caching disabled appear to raise timeouts with AWS ELB. Now I jump to that conclusion by comparing the output of sslscan from the C++ servers to the Go ones, however when using openssl CLI it will go ahead and use an ECC cipher without issue. Nice. 10) AWS ELB has configuration for health check intervals and it pretty much has no meaning as you will receive 6 connections per second from all over the world no matter what you set. How 6 requests/second can overload OpenSSL is beyond my understanding. I'm comparing to a server written in Go using BoringSSL, and another C++ server using bespoke (probably derived from the examples) HTTPS server. Both of those have no disconnects or errors. The latter does not implement keepalives at all and just closes after each request. Possibly irrelevant but the Go server has 50/50% TCP RSTs driven by the client and server, suggesting a keepalive period is too short, the C++ server is somehow 100% driven by the client which makes no sense at all if it closing after a response. It is possible they messed up with SSL shutdown and just close out the socket, apparently the session cache is only written on a clean SSL shutdown. When I have session caching enabled I see 100% TCP RSTs generated by my C++ server app, most likely because the idle timeout is too short. AWS ELB is apparently hard coded to 60s. I have one thread that is shared between ASIO TCP server (with no connections, lol) and Beast/HTTPS. the other C++ is one thread dedicated to HTTPS serving. If the health check errors are due to timeouts this should be a complete apples-to-apples comparison as the only code here should be async_accept and async_handshake? I need to raise up with AWS support soon, I'm waiting on one last test with a forced ECC cipher and a manually set cache size limit and timeout. MrMoo fucked around with this message at 05:12 on May 2, 2019 |
# ? May 2, 2019 04:56 |
|
MrMoo posted:What's the goal beyond boost::asio::async_read(s, boost::asio::buffer(data, 1u), handler);? Pretty much just trying to make it read nicer and make it so the caller doesn't have to manage the buffer lifetime. My next step is to compose these little operations into more complex stateful ones implementing a protocol.
|
# ? May 2, 2019 15:05 |
|
The forced ECC build is pending verification because ECS load balancers keep pointing to the wrong target group. So disabling that in another build and test again. I'll definitely laugh if it turns out AWS ELB requires default_workarounds to be enabled and everything is a red herring.
|
# ? May 2, 2019 16:51 |
|
I'd like to learn modern C++. Is there a good intro book for that? It seems like Stroustrup's book is more of a reference and Koenig/Moo is almost 20 years old. I had done some C++ over a decade ago in high school, but kinda stopped there. For reference, I'm an adequate programmer. I'm comfortable with C and basic object-oriented concepts.
|
# ? May 3, 2019 20:01 |
|
Probably Meyers Effective Modern C++. I dont think its been updated for C++17, but thats easy enough to sort out. This isnt bad either, for a high level overview: https://ds9a.nl/articles/posts/cpp-intro/
|
# ? May 4, 2019 00:17 |
|
A Tour of C++ has been updated for C++17, you could try checking that out. It is not an intro to programming book and is more of an overview of C++. The target audience seems to be experienced developers who've taken a break from C++ and is now trying their hand at it again. (Note that I've only read the 1st edition of this book so I don't know how adequately it covers the new stuff.)
|
# ? May 4, 2019 18:55 |
|
MrMoo posted:The forced ECC build is pending verification because ECS load balancers keep pointing to the wrong target group. So disabling that in another build and test again. I'll definitely laugh if it turns out AWS ELB requires default_workarounds to be enabled and everything is a red herring. Almost everything a red herring, finger pointing to IO context concurrency hint value of 1 being utterly broken. The thread stalls on a particular 2-cpu EC2 node and nowhere else. Such fun waiting 30-mins to get a Docker image build and another 30 for it to be deployed for a runtime of 2 minutes to flag success or failure.
|
# ? May 4, 2019 22:39 |
|
I tend to do this a lot when I want a thread-safe data structure that I know will be used in multiple threads:code:
code:
e: I guess what would be great is some kind of either runtime or compile time thing that alerts me to non-protected uses of the vector, but I know this is c++ and not rust so I don't know if that exists. baby puzzle fucked around with this message at 21:32 on May 7, 2019 |
# ? May 7, 2019 21:23 |
|
That is the right thing to do. You protect it whenever you modify or access/loop the vector. Better: lock free structures. That is, structures that are thread safe and they accomplish that without the use of a mutex or lock. One example is https://www.boost.org/doc/libs/1_63_0/doc/html/lockfree.html . There are others as well.
|
# ? May 7, 2019 22:29 |
|
Hello friends Because I'm a masochist, I'd like to program a DOS game, directly on the VGA hardware, either mode 13 or mode-X I know C and C++ very well, but I've only ever learnt their standard libraries and and modern libraries like SDL and SFML and never did things on the "metal" like bios interrupts, dos.h and mem.h from the cool old days of DOS programming I have access to a real DOS PC with 6.22 and Windows 3.1, also DOSBox, various Borland and MS compilers from the late 80's and early 90's - what's the best original compiler? I looked into DJGPP but I probably want real mode not protected mode? Can anyone recommend some good books from back in the day? Covering things like the DOS API/Interrupts, VGA hardware, Borland/MS C, maybe some Turbo Assembler/Microsoft Assembler? I feel like things like the oft recommended Mike Abrash books are for people who already know the basics of DOS and VGA programming and I'd need to start simpler Thank you
|
# ? May 7, 2019 22:54 |
|
c0burn posted:Hello friends
|
# ? May 7, 2019 22:58 |
|
Ralith posted:Are you interested in learning how to do things on the metal, or in learning how legacy systems used to work? Those are very different these days; all the interfaces you're talking to are either completely dead, or emulated by hardware that works very differently internally. I'd like it to work on a real DOS PC and DOSbox From some googling, you call some BIOS interrupts, set some registers and poke at the VGA memory directly - am I using the wrong terminology when I say "metal"?
|
# ? May 7, 2019 23:12 |
|
Volguus posted:That is the right thing to do. You protect it whenever you modify or access/loop the vector. Better: lock free structures. That is, structures that are thread safe and they accomplish that without the use of a mutex or lock. One example is https://www.boost.org/doc/libs/1_63_0/doc/html/lockfree.html . There are others as well. but.. that relies on me not being an idiot.. Actually sometimes I name things like myVector_protected, or something obnoxious when I know it is used in different threads and I need the constant reminder. I use lock-free queues for sending messages between threads, and I think they are pretty cool. But its arrays/vectors/maps where I tend to get mixed up...
|
# ? May 7, 2019 23:19 |
|
c0burn posted:I'd like it to work on a real DOS PC and DOSbox Its the right terminology but the wrong era. What Ralith is saying is that the low-level programming skills you learn programming a DOS-era computer at the level you described wont translate to programming anything modern at the equivalent level. The at the metal level youre talking about simply doesnt exist for something like a Cortex-M series microcontroller, or in the case of modern PCs its emulated for backwards compatibility. Thats not to say it wouldnt be fun to do! Just be aware that it might not be helpful in TYOOL 2019
|
# ? May 8, 2019 00:04 |
|
Oh I see. Yeah I get that it won't translate to modern hardware. This is just for fun!
|
# ? May 8, 2019 00:11 |
|
|
# ? Jun 8, 2024 14:24 |
|
baby puzzle posted:but.. that relies on me not being an idiot.. Actually sometimes I name things like myVector_protected, or something obnoxious when I know it is used in different threads and I need the constant reminder. Well, encapsulate the vector in your own class where you do protect stuff. You would have to provide a different way to iterate over elements, you cannot just expose the begin/end, or any other bit more convoluted operation, but other than that, you can do it.
|
# ? May 8, 2019 00:35 |