|
Plorkyeran posted:Not being able to bind an lvalue reference to a temporary was a restriction added fairly late in the standardization process, and it's a rare example of C++ forbidding something because it's a footgun rather than because it can't work. Maybe even the only one? (I still think that the rule-of-3 should've been language level rule.)
|
# ? Sep 16, 2016 18:28 |
|
|
# ? Jun 3, 2024 07:47 |
|
Sintax posted:Im not looking to argue or anything but you misinterpreted my post and assumed I didn't know how to use a fundamental concept, then misinterpreted it again and assumed I want you to teach me how to use it. I'll stick to my programming for dummies book thank you I mean, you wrote &warnings=std::cout. You don't know how to use a fundamental concept.
|
# ? Sep 16, 2016 18:55 |
|
Xarn posted:Maybe even the only one? (I still think that the rule-of-3 should've been language level rule.) I really get the impression that stuff like this arose out of post-standardization usage. Everything looked fine on paper but then real-world cases made it obvious that some additional rules were necessary. Sorta like how SFINAE inadvertently opened the door to template metaprogramming.
|
# ? Sep 16, 2016 19:47 |
|
Sintax posted:Im not looking to argue or anything but you misinterpreted my post and assumed I didn't know how to use a fundamental concept, then misinterpreted it again and assumed I want you to teach me how to use it. I'll stick to my programming for dummies book thank you To be fair to him, from looking at your code and trying to work out what exactly you're trying to do, I get the impression that you don't understand a lot of fundamental concepts in C++ and perhaps programming in general. Which isn't a bad thing, everyone starts from somewhere, but right now you come across as someone who just learned how to hammer, and is eagerly trying to hammer a screw in while telling other people how precious they are for telling you you're doing something wrong.
|
# ? Sep 16, 2016 20:03 |
|
Is there a way to get Visual Studio to show only the filename when showing errors? It's really hard to read template errors when I have a project deeply nested in some weird directory.
|
# ? Sep 19, 2016 20:05 |
Is there a standard way to do RAII with temporary files, either in the STL or in boost? I could roll my own, but I'd rather use an accepted approach if possible. This is on unix and has no need for portability with windows, if that matters.
|
|
# ? Sep 20, 2016 03:08 |
|
VikingofRock posted:Is there a standard way to do RAII with temporary files, either in the STL or in boost? I could roll my own, but I'd rather use an accepted approach if possible. This is on unix and has no need for portability with windows, if that matters. You mean like make a file named by a UUID generated in the constructor and then destroy that file in the destructor? Don't really think there's a standard way to do that. Though there are a few standards on generating a UUID and making a RAII UUID-named temp file would be pretty simple. Depending on what you want the file for, you may want some other filelike object instead, like a FIFO.
|
# ? Sep 20, 2016 03:49 |
|
VikingofRock posted:Is there a standard way to do RAII with temporary files, either in the STL or in boost? I could roll my own, but I'd rather use an accepted approach if possible. This is on unix and has no need for portability with windows, if that matters. The C library tmpfile creates files that are guaranteed to get cleaned up when the FILE* it returns is closed, including on program termination (as long as abort() isn't used, which would bypass RAII anyway). This alone might meet your needs, but you could also write a simple file-closing RAII wrapper.
|
# ? Sep 20, 2016 03:57 |
|
On UNIX you can delete the file after opening it and it'll be cleaned up when the last fd is closed (including via abort() or a crash or sudden power off).
|
# ? Sep 20, 2016 04:21 |
I should mention that I actually do need the filename, since I need to pass it to a subprocess. If there's no standard way of doing this, maybe I'll just write an RAII wrapper around mkstemp. Thanks anyways.
|
|
# ? Sep 20, 2016 05:02 |
|
VikingofRock posted:I should mention that I actually do need the filename, since I need to pass it to a subprocess. If there's no standard way of doing this, maybe I'll just write an RAII wrapper around mkstemp. Thanks anyways. Are you trying to send data to or from the subprocess? Use a FIFO.
|
# ? Sep 20, 2016 05:07 |
|
Or it can take the fd if you're not setting CLOEXEC.
|
# ? Sep 20, 2016 05:13 |
leper khan posted:Are you trying to send data to or from the subprocess? Use a FIFO. So as to avoid the XY problem, I'm just gonna type out the full thing I want to do: I want to create a file, write some data to it, and then call a third-party command line utility which takes the name of the file as one of the command line arguments. That process uses the data in the file to do some analysis, and then it prints the result to stdout, which I am then reading and using in my main program. I want to make sure that the file gets deleted so that I don't have a bunch of these cluttering up the filesystem. I'm gonna be doing this O(10,000) times, across O(100) threads, and the program might get killed at any given moment because of the way that job management works on the supercomputer I'm running this on. I think what I said before will let me accomplish this, but it's entirely possible I am missing something fundamental here, so let me know if it sounds like that's the case.
|
|
# ? Sep 20, 2016 05:45 |
|
VikingofRock posted:So as to avoid the XY problem, I'm just gonna type out the full thing I want to do: I want to create a file, write some data to it, and then call a third-party command line utility which takes the name of the file as one of the command line arguments. That process uses the data in the file to do some analysis, and then it prints the result to stdout, which I am then reading and using in my main program. I want to make sure that the file gets deleted so that I don't have a bunch of these cluttering up the filesystem. I'm gonna be doing this O(10,000) times, across O(100) threads, and the program might get killed at any given moment because of the way that job management works on the supercomputer I'm running this on. Pretty sure that's what FIFOs are for. They're like files in the file system except they don't get written to disk so the performance characteristics should be much better. If you're doing this 10k times, it probably matters. https://www.freebsd.org/doc/en_US.ISO8859-1/books/design-44bsd/overview-io-system.html 2.6.1
|
# ? Sep 20, 2016 06:18 |
|
VikingofRock posted:So as to avoid the XY problem, I'm just gonna type out the full thing I want to do: I want to create a file, write some data to it, and then call a third-party command line utility which takes the name of the file as one of the command line arguments. That process uses the data in the file to do some analysis, and then it prints the result to stdout, which I am then reading and using in my main program. I want to make sure that the file gets deleted so that I don't have a bunch of these cluttering up the filesystem. I'm gonna be doing this O(10,000) times, across O(100) threads, and the program might get killed at any given moment because of the way that job management works on the supercomputer I'm running this on. Does the third party command line accept input from stdin? (canonically, '-' as an input filename) If so, you can pass data via a pipe.
|
# ? Sep 20, 2016 07:21 |
b0lt posted:Does the third party command line accept input from stdin? (canonically, '-' as an input filename) No, unfortunately not. Actually, I was simplifying a bit in my post--what it really takes is an argument that looks like 'source_file.fits[sky=region(region_file.reg)]', where "region_file.reg" is the name of the file that I want to be temporary, and "source_file.fits" is some other file containing different data.
|
|
# ? Sep 20, 2016 07:29 |
|
In that case you want mkstemp(3) or one of the related functions.
|
# ? Sep 20, 2016 08:05 |
|
leper khan posted:Pretty sure that's what FIFOs are for. They're like files in the file system except they don't get written to disk so the performance characteristics should be much better. If you're doing this 10k times, it probably matters. A FIFO won't work if the program does random access. If you want Linux to guarantee that the file is not left around, then you need to unlink the file after creating it, or open it with the O_TMPFILE flag. You can still get a file path to a file descriptor if you use /proc/self/fd/$FDNUMBER as the file path. On the other hand, so long as you create your temporary files in /tmp and make proper use of RAII for cleanup you probably don't need to care about making the kernel ensure it's cleaned up, since on reboot those files are cleared away, and at runtime the only way for them to pile up is if the program crashes, and eventually some process will clean away that temporary file too.
|
# ? Sep 20, 2016 08:15 |
|
VikingofRock posted:So as to avoid the XY problem, I'm just gonna type out the full thing I want to do: I want to create a file, write some data to it, and then call a third-party command line utility which takes the name of the file as one of the command line arguments. To start, Jsor asked a similar question recently in the general thread, my response: ExcessBLarg! posted:On Unix/Linux you can used a named pipe (FIFO). Like the "create a file" workaround it requires writing an inode somewhere to the file system with it's associated permission and cleanup issues, but you'll be writing to a pipe at least and not having to write the whole file. If you only have to support "recent" versions of Linux (3.17+), I'd look into memfd_create(2), which creates an anonymous file (not backed by any store) and returns a file descriptor that you can write/mmap, and then "pass" to the other program using /dev/fd. If you only have to support "less recent" versions of Linux (3.11+) you can use open(2)'s O_TMPFILE argument. This does create an inode in the file system, but you don't have to worry about generating a unique name and unlinking/cleanup. If you go this route you may want to use a tmpfs filesystem (e.g., /run/shm) to avoid having the inode written to a persistent file system (disk). If you have to support non-recent Linux or other Unixes then mkstemp(3) followed by an unlink will work, as mentioned by others. I'd still try to put this on a tmpfs. leper khan posted:Pretty sure that's what FIFOs are for. They're like files in the file system except they don't get written to disk so the performance characteristics should be much better. If you're doing this 10k times, it probably matters.
|
# ? Sep 21, 2016 16:34 |
As far as I know the third-party utility does need random access to the file, so I ended up writing an RAII wrapper around mkstemp/unlink. Thanks for the help guys.
|
|
# ? Sep 21, 2016 20:32 |
|
I can't get C++ to work in ST3 on Win10 x64 with external class files (Class.h and Class.cpp) and my current build system. Is there a build-system solution to this or something else? I'm not a big fan of handing over everything to an IDE when I'm picking up a new language.
|
# ? Sep 25, 2016 16:26 |
|
ufarn posted:I can't get C++ to work in ST3 on Win10 x64 with external class files (Class.h and Class.cpp) and my current build system. Is there a build-system solution to this or something else? Well, unfortunately, Visual Studio is by far the simplest choice when doing C++ development on Windows, so your heuristic is leading you astray in this case.
|
# ? Sep 25, 2016 16:58 |
|
ufarn posted:I can't get C++ to work in ST3 on Win10 x64 with external class files (Class.h and Class.cpp) and my current build system. Is there a build-system solution to this or something else? Without any information about your build system, what kind of help do you expect? Also use Visual Studio.
|
# ? Sep 25, 2016 21:34 |
|
Xarn posted:Without any information about your build system, what kind of help do you expect? If people don't have it working on ST3, they don't have a working build system. The default build system for C++ in ST3 is specifically for single files.
|
# ? Sep 25, 2016 22:04 |
|
ufarn posted:ST3's build systems are just based on JSON files: http://sublimetext.info/docs/en/reference/build_systems.html If you want to learn a language (as opposed to build tools) take the easiest path to learn the language: use and IDE which can help with the boring and not-so-interesting tasks of building things. Visual Studio (community edition is free) can help a lot and lets you concentrate on the language itself not on how you build things. Yes, you should learn how to build an executable from the command line (make, cmake, msbuild or this ST3 thing that I've never heard of before) without the aid of an IDE, but that has nothing to do with the language itself. You can use make to build c, c++, java or whatever other things you want. And probably the same goes for that ST3. Build tools != language.
|
# ? Sep 26, 2016 00:07 |
|
I actually think IDEs make things a lot worse when it comes to picking up a new language. Maybe if it's the first time you try coding and want to move a turtle in different directions, but all the magic involved in creating external classes in C++ is one of the things that really put me off IDEs. I don't have a problem with using them for programming in general, I just don't see the point of programs where you struggle to even find the build button.
|
# ? Sep 26, 2016 10:27 |
|
ufarn posted:I actually think IDEs make things a lot worse when it comes to picking up a new language. Maybe if it's the first time you try coding and want to move a turtle in different directions, but all the magic involved in creating external classes in C++ is one of the things that really put me off IDEs. I don't have a problem with using them for programming in general, I just don't see the point of programs where you struggle to even find the build button. IDEs make it easy to find the build button. It looks like this: |>
|
# ? Sep 26, 2016 13:20 |
|
ufarn posted:all the magic involved in creating external classes in C++ is one of the things that really put me off IDEs What? As long as you avoid MFC - and if you're learning C++ in 2016 then you probably should avoid MFC - Visual Studio does basically no magic when it comes to creating C++ code. Class creation is very straightforward and masks no part of the process. As for your immediate problem, I think you're asking how to write one of these ST3 JSON files - which are used to invoke a compiler command - so that it will build a C++ executable whose source is contained in multiple .h/.cpp files. Is that right? If that is right and you're trying to figure out how to get your text editor to invoke your compiler, then congratulations ST3 is an IDE
|
# ? Sep 26, 2016 14:38 |
|
ufarn posted:I actually think IDEs make things a lot worse when it comes to picking up a new language. Maybe if it's the first time you try coding and want to move a turtle in different directions, but all the magic involved in creating external classes in C++ is one of the things that really put me off IDEs. I don't have a problem with using them for programming in general, I just don't see the point of programs where you struggle to even find the build button. Put up or shut up. Either go with "blah blah, IDEs are too magic" and don't try to use ST3's weird, bespoke JSON build tool, invoking cl.exe from cmd instead (its not actually that hard), or admit that you just want ST3, there is nothing wrong with that (well, except the build tool seems poo poo).
|
# ? Sep 26, 2016 21:25 |
I remember my first run-in with MSVS for C++. I couldn't for the life of me figure out how to just run a single main file, so i gave up and kept playing around in Dev-C++. IDEs can seem inconquerable and bloated for anyone just starting up, because they're made for bigger projects, and typically left out a lot of ease of use like just being able to load in a main file and compile it without any fuss or projects or poo poo.
|
|
# ? Sep 27, 2016 02:20 |
|
Does Visual Studio still try to foist MFC on you if you're not consciously avoiding it, or has it become sane now?
|
# ? Sep 27, 2016 07:05 |
roomforthetuna posted:Does Visual Studio still try to foist MFC on you if you're not consciously avoiding it, or has it become sane now? You only get MFC if you use the "MFC Application" wizard, or select the MFC box in the "Win32 Project" wizard settings for a DLL or static library type project. It does force precompiled headers on you, unless you choose "Empty project" in the "Win32 Project" wizard. Which means you will be confused about what stfafx.h and stdafx.cpp are doing in your project, and why those seemingly pointless files are required to build.
|
|
# ? Sep 27, 2016 07:14 |
|
nielsm posted:You only get MFC if you use the "MFC Application" wizard, or select the MFC box in the "Win32 Project" wizard settings for a DLL or static library type project. It only forces precompiled headers if you select Win32 project -> Windows application subtype, otherwise it just has it checked by default. (No idea why it still thinks that stdafx.h is neccessary for Windows application, and really should let you just uncheck it.)
|
# ? Sep 27, 2016 08:08 |
|
roomforthetuna posted:Does Visual Studio still try to foist MFC on you if you're not consciously avoiding it, or has it become sane now? The upcoming version doesn't even install MFC by default anymore.
|
# ? Sep 27, 2016 17:50 |
|
Plorkyeran posted:The upcoming version doesn't even install MFC by default anymore. Is the new installer any good? I just remembered I got an email while on vacation to test it.
|
# ? Sep 27, 2016 20:19 |
|
Well it installs the program without making your computer unusable for 8 hours in the process, so I guess so?
|
# ? Sep 27, 2016 23:48 |
|
I've been writing C for the last few years and would really like to brush up on c++ for job hunting. What are some good ways/sites to practice c++ coding? I found HackerRank earlier today but so far the problems have been pretty easy and I'm worried I'll blitz through them in a week or two.
|
# ? Oct 6, 2016 03:21 |
|
That site has hundreds of challenges and competitions every week, the quality of challenges is a bit low and the competitions are like 99% dynamic programming.
|
# ? Oct 6, 2016 03:28 |
|
LLSix posted:I've been writing C for the last few years and would really like to brush up on c++ for job hunting. What are some good ways/sites to practice c++ coding? Make some bug fixes/performance improvements for RethinkDB.
|
# ? Oct 6, 2016 06:37 |
|
|
# ? Jun 3, 2024 07:47 |
|
LLSix posted:I've been writing C for the last few years and would really like to brush up on c++ for job hunting. What are some good ways/sites to practice c++ coding? I found HackerRank earlier today but so far the problems have been pretty easy and I'm worried I'll blitz through them in a week or two. Write a little game clone using as much modern C++ features as possible, but be sure to throw away the code afterwards and make a mental note of what worked well for you and what did not.
|
# ? Oct 6, 2016 12:15 |