« first day (1014 days earlier)      last day (1830 days later) » 

5:27 AM
I need to std::string_view, std::string, etc. which can access characters which come in a rotated fashion: suppose the source string was 01234567, but in the destination computer the string appears as 32107654.
     static constexpr CharT access(const CharT* str, std::size_t index) {
            str += index/sizeof(CharT);

            auto offset = sizeof(CharT) - index%sizeof(CharT) - 1;

            auto bytes = reinterpret_cast<const unsigned char*>(str);
            return CharT(bytes[offset]);
        }
I don't know if it's possible to embed that kind of access pattern into std::char_traits or I'll have to roll my own implementation of string_view/string
I think the problem is exactly identical to reading a big-endian string in a little-endian computer and vice-versa.
 
Have you considered deep copying? Especially if you have many accesses, the deep copy solution will win.
 
Nope but that would require copying two times even for small computations.
 
Or once if you return the new string
 
?
 
When you copy into the new string, perform the string rotation. Return the new string.
You can do it "in place" if you use a buffer, probably thread_local. This is what I did when I needed to write something similar.
 
 
5 hours later…
10:52 AM
1529
Q: What are move semantics?

dicroceI just finished listening to the Software Engineering radio podcast interview with Scott Meyers regarding C++0x. Most of the new features made sense to me, and I am actually excited about C++0x now, with the exception of one. I still don't get move semantics... What are they exactly?

 
11:09 AM
hi guys!
This sounds like a common question but its never quite answered online. Why use virtual functions? I know that using a virtual function means that the function is only used for the subclasses implementation of it. However, runtime execution will be much slower than compile time. Therefore, why use virtual functions (apart from ease of reading the code)?
 
11:24 AM
like why would i want something to be executed at runtime instead of compile time?
 
nwp
Because sometimes execution depends on things known only at runtime, for example because the user selects what should be executed or because execution requires accessing files which have content not known at compile time.
 
11:39 AM
why cant normal functions be written to deal with this?
 
nwp
The idea is from OOP. You describe every object in the real world, like a file or a network socket with a class that has functions like read and write. And then you have functionality like write_object which writes bytes. You want to make it so that write_object can simply say output.write(bytes); without having to know if output is a file or a socket, because it doesn't matter. Also this will be decided at runtime.
So you make write(Bytes); a virtual function of some IOClass and have both File and Socket inherit from that and overwrite the write function in order to implement that.
You don't have to use inheritance to implement this. You can also use function pointers with a void * and some casting instead like C does it, but that is less convenient.
 
 
1 hour later…
1:01 PM
@Permian "Therefore, why use virtual functions (apart from ease of reading the code)?" - if you ignore that readadility of the code leads to fewer errors/suport of this code being less consuming, then there is none.
 
@Permian because function pointers are annoying to get right, particularly when you need a specific set and they may not be defined in code you have access too.
 
 
7 hours later…
8:13 PM
Yo
How can I make enum class with 100 entries as flags?
 

« first day (1014 days earlier)      last day (1830 days later) »