How similar are Boost.Filesystem and the C++ standard filesystem library?

There are a number of differences. Some were, I believe, Boost changes that were never propagated. For example, there is no path.filename_is_dot() query (as discussed below, it would be less useful in std::filesystem anyway). There was also a good bit of late-breaking news on this front: Support for non-POSIX-like filesystems: Specify whether a string is … Read more

How do you implement Coroutines in C++

Yes it can be done without a problem. All you need is a little assembly code to move the call stack to a newly allocated stack on the heap. I would look at the boost::coroutine library. The one thing that you should watch out for is a stack overflow. On most operating systems overflowing the … Read more

Why is there no implicit conversion from std::string_view to std::string?

The problem is that std::string_view -> std::string makes a copy of the underlying memory, complete with heap allocation, whereas the implicit std::string -> std::string_view does not. If you’ve bothered to use a std::string_view in the first place then you obviously care about copies, so you don’t want one to happen implicitly. Consider this example: void … Read more

“constexpr if” vs “if” with optimizations – why is “constexpr” needed?

This is easy to explain through an example. Consider struct Cat { void meow() { } }; struct Dog { void bark() { } }; and template <typename T> void pet(T x) { if(std::is_same<T, Cat>{}){ x.meow(); } else if(std::is_same<T, Dog>{}){ x.bark(); } } Invoking pet(Cat{}); pet(Dog{}); will trigger a compilation error (wandbox example), because both … Read more

Why doesn’t an if constexpr make this core constant expression error disappear?

The standard doesn’t say much about the discarded statement of an if constexpr. There are essentially two statements in [stmt.if] about these: In an enclosing template discarded statements are not instantiated. Names referenced from a discarded statement are not required ODR to be defined. Neither of these applies to your use: the compilers are correct … Read more