« first day (1453 days earlier)      last day (1383 days later) » 

10:04 AM
whats the difference between direct.empty() and empty(direct) ???
 
one is a function member call and the other is calling a free function with direct as a parameter

There was some proposal to make them the same I think. Universal function call syntax or so, but I don't think it's going to get into the standard
 
ok cool!
 
Heeeeey, I got a small project that I am working on, currently got like 2 converter methods and one method that reads from fstream.
I would like to abstract these methods to their own "utility class". What do you guys usually name there helper/utility classes?
Just naming it utility or helper doesn't really say what the class do in this case
 
why put them in a class if they're unrelated? You can just put them in a namespace, right?
 
10:12 AM
That's true, however what they have in common is that they help with converting strings and reading from the file. It feels unnecessary to have them in main.
 
you can just put them as free functions in a namespace
 
11:06 AM
true, I'll guess I will do that, cheers
 
 
6 hours later…
5:29 PM
Hi all!
 
'ello
 
So , uhm, I'm having trouble with unicode here, on windows 10, sigh.
Background:
 
okay.
 
Cross-platform application in qt5, front-end purely written in qt. Backend written in pure std, and stl + boost.
Front-end shows the user a QFileSystemdialog, that thing returns a QString, so far so good, the string is (or is it?) UTF-8 encoded. The QWdiget's in the GUI show the characters in that string just fine.
Then, we have to pass this string to std::fstream, on Windows 10, x64, licensed, version 2004.
And, uhm, it doesn't work.
 
QStrings are by default UTF-16 on Windows
 
5:33 PM
1. passing the string as is, i.e. std::string str = qStringFileName.toUtf8().toStdString(); std::fstream{str} is broken.
2. `std::filesystem::u8path(qStringFileName.toUtf8().toStdString()` is broken:

> No mapping for the Unicode character exists in the target multi-byte code page
What should I do? A colleague's Windows 10 (in the office) works fine with QTextCodec::codecForLocale()->fromUnicode(path).toStdString(), but this is broken on my Windows 10 machine, with symptoms similar to point 1 above: question signs in the std::string that we pass to std::fstream.
I'm getting really desperate, since this works fine on Linux without spending an entire working day banging our heads against the wall
Any ideas?
 
Are you using a new enough compiler to use std::filesystem::path instead? A Windows implementation will normally support UTF-16 encoding for the path, so you can avoid all the conversion between UTF-16 and UTF-8.
 
Yes I am, what are the methods to call exactly?
 
I guess an ifdef with windows
std::filesystem::path(qStringFilename.toStdWString())
and for linux just
std::filesystem::path(qStringFilename.toUtf8())
 
What is this and how do I fix it, btw?

> No mapping for the Unicode character exists in the target multi-byte code page
This occurs when trying to use std::filesystem::u8path
 
I haven't used Qt recently enough to give any specifics for it, but path has some ctors that are supposed to handle conversions which may make your life easier. For example, see numbers 7 and 8 at: en.cppreference.com/w/cpp/filesystem/path/path
 
5:49 PM
I'm coding a quick typedef test right now, to see if that helps
The constructors look scary to me since I have yet to learn what a std::locale is.
 
Actually, rereading that, I'd probably just always use stoStdWString(), which should go to ctor #6, which will pass straight through on Windows, and automagically convert to UTF-8 on Linux.
 
Which requires an #ifdef :\
 
@iksemyonov Why would that require an ifdef? You're passing in UTF-16 either way, and path has a native_type that represents whatever the native file system expects, so it converts from what you give it to that encoding.
 
@JerryCoffin I'm trying out PeterT's suggestion above
To fork into std::string and std::wstring modes.
 
Oh, I see. Not what I'd do, given that path already has overloads specifically to deal with this sort of situation.
 
5:53 PM
I'm writing a cross-platform application, remember.
@JerryCoffin See if something works, at the very least
Then improve
 
Yes, exactly--and std:filesystem::path is designed specifically to let you do this portably without an ifdef.
 
I've never felt so dumb, to be honest. I've done weirdest debugging tasks against a broken compiler at Intel. This stuff, especially getting a project to build on VS2019, is a nightmare compared to that. Go figure.
 
I think we're all affected somewhat similarly. Some things are inherently complex, and most of us are sort of all right with that. It's a whole different story when they're inherently simple, but become complex for almost entirely arbitrary reasons, typically that people simply wouldn't agree on something and just go with it.
 
While we're at it. I have a point in the application where a CLI utility accepts a char * [], as they all do. Can I convert this to a std:wstring? Or should I fork here, too, for a wchar * []?
@JerryCoffin Yeah, probably. "21 standard".
 
@iksemyonov If memory serves, you can convert it to a wstring, but if memory serves, it just widens each char to wchar_t individually, and stores them. If a char * contains UTF-8, it won't (at least if memory serves) convert it to UTF-16, or anything like that.
 
6:03 PM
Oh Lord.
I think I'll use a QString at that point.
 
6:23 PM
Well, the std::wstring approach seems to have worked, though it would require a rewrite of half the interfaces and of course the command line is broken too.
Damn, why not just use English letters when working on a PC..
 
Actually, re-checking things, you can't just initialize a wstring from a char *. Simply doesn't compile.
 
Used this in the end for the console part:
std::wstring wstrFilePath = std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(strFilePath);
"deprecated", but I don't care much
 
7:00 PM
Well, now I'm lost again
How do I construct a std::filesystem::path from std::wstring?
I need this in order to perform some filesystem operations on those strings representing paths
Constructor 7 for path requires a locale, which I have no idea how to build
 
 
2 hours later…
9:13 PM
What happens if you `remove(...)` *(also `DeleteFileA(...)` or `unlink(...)`)* a file with an `fopen(...)` stream?

Will the file still be available to handle using the stream or will it become undefined to use the stream?
 
9:43 PM
...
 
@Lapys Depends on the system. On Linux (and most UNIX-like systems) if you unlink a file while it's open, you can continue reading/writing as long as it's open, but it'll be deleted as soon as you close it (in fact, when you need a temporary file, it's pretty common to open a file, then immediately delete it). On Windows (if memory serves) attempting to delete a file while it's open will simply fail.
On the other hand, if you actually want that behavior, Windows allows you to specify FILE_FLAG_DELETE_ON_CLOSE when you call CreateFile (assuming you do call it directly), which gives pretty much the same effect, but in a more self-explanatory manner.
 
10:06 PM
Thanks @JerryCoffin
 

« first day (1453 days earlier)      last day (1383 days later) »