« first day (367 days earlier)      last day (4564 days later) » 

12:00 AM
5 mins ago, by Luc Danton
'Using RAII' doesn't mean writing special members that handle resource acquisition by the way.
struct foo { std::vector<bar> bars; }; is a type that uses RAII.
 
no but not failing at construction would be
 
What?
 
for sure, I would agree
 
std::vector and std::string can all fail at construction.
So would opening a file.
 
And there's nothing wrong with that. If a constructor does not run to completion the corresponding destructor is not called.
 
12:01 AM
so what happens to the object?
 
@CaptainGiraffe There's no object if construction fails.
 
@CaptainGiraffe There is no object before the constructor completes (there are a few exceptions, but I don't think they're relevant).
 
Awesome, I'm learning
Exceptions needs to be enabled right?
 
Exceptions are part of the language proper and are not optional. If you don't have exceptions you're not really using C++.
You'd be using a dialect/extensions.
(Or maybe that's not what you mean by enabling exceptions?)
 
@Luc, fair call, I remember using a MS VS compiler having to turn on the exceptions
So, to recap, a copy constructor would not be RAII, i.e. big three goes against raii?
 
12:05 AM
No, not at all.
 
No those are orthogonal.
 
The rule of three is about correct value semantics.
 
Note that forbidding copy and assignment (for user code) counts as following the rule of three.
 
In particular in (This is where I go wrong, non raii world)
for sure
 
12:09 AM
Neat, GCC implements std::thread::hardware_concurrency.
 
But the rule of three is commonly applied to the use of any dynamic resource. C(const& C original){ *expensive=&original.expensive }
 
Yes, when manually enabling RAII for a class, it's common to have to follow the rule of three.
 
and C(const C& original ){ if ( this == &original) please_not_me )
 
Those copy constructors aren't looking terribly good tbh.
 
oops not the copy ctor of course =)
 
12:11 AM
I usually don't need to check for self-assignment.
 
that would be horrible by any HP lovecraft novel =)
 
(Assuming that's what you meant, and not "self-copy".)
The way I think of it RAII just means that a class takes responsibility for all the resources it owns, leaving the client free to care about what matters.
 
I like to think in terms of invariants but I was taught invariants before learning C++ so YMMV.
Also modular design.
And opaque types.
 
ok C::operator=(const C& rhs ){ assert(&rhs!= this) }
well nevertheless its not really useful and my apologies
 
Why is c = c; an error? int i = 0; i = i; is not an error.
 
12:15 AM
the assert is not from cassert, it is a simple if statement saying return, we don't belong here.
 
You should pick a better (and non-clashing) name (isn't it reserved?).
 
That would detract from the point in the discussion.
 
194
A: What is the copy-and-swap idiom?

GManOverview Why do we need it? Any class that manages a resource (a wrapper, like a smart pointer) needs to implement The Big Three. While the goals and implementation of the copy-constructor and destructor are straightforward, the copy-assignment operator is arguably the most nuanced and difficul...

 
@CaptainGiraffe How does it return the right thing?
Or do you mean it's pseudo-code?
 
@LucDanton *this would be a simple cop-out.
@LucDanton Yes In mu drunken stupor I wrote assert to provoke something I did not intend to provoke.
 
12:18 AM
Okay.
 
I though assert meant in pseudo, we really don't care about this case =)
 
In computer programming, an assertion is a predicate (for example a true–false statement) placed in a program to indicate that the developer thinks that the predicate is always true at that place. For example, the following code contains two assertions: x := 5; {x > 0} x := x + 1 {x > 1} x > 0 and x > 1, and they are indeed true at the indicated points during execution. Programmers can use assertions to help specify programs and to reason about program correctness. For example, a precondition — an assertion placed at the beginning of a section of code — determines the set of states und...
There are at least two usages of assertion that are not similar in nature, to compound the confusion.
 
Please, we are not doing aspect, and not scheme.
 
My language doesn't have a term for assertions :(
 
You should be lucky, you are immune to scientologists.
 
12:21 AM
Wouldn't 'predicate' (predicado?) be close in meaning?
 
Not really. A predicate can be evaluated to true or false.
An assertion specifies that a predicate is true.
 
Well when I write a predicate to an algorithm, that can be anything I'd like
Thanks R
 
Isn't there a logician view on things where everything is either true, or ill-formed?
 
The excluded third maybe
 
Google Translate gives "afirmação". That's a close meaning, but we commonly use that for "statement" (the legal or linguistic meaning, not programming).
 
12:25 AM
A statement is either true or false there is no statement providing an answer in between.
 
Neat, when wrapping an API I can use a deleter type with overloaded operator() so that I can use only that type with std::unique_ptr.
 
you can?
 
I just did!
 
crap that is just awesome =)
Now I need to go into hiding for next years classes.
 
@LucDanton I use std::function<void(T*)>.
Or maybe that's not what you meant.
 
12:31 AM
Yeah, the overloads corresponds to different API types.
Hence I will have a std::unique_ptr<api::foo, deleter>, an std::unique_ptr<api::bar, deleter>.
 
I'll do template <typename T> using simple_ptr = std::unique_ptr<T, std::function<void(T*)>>; in the future (come on GCC, gimme template aliases, please!).
 
@RMartinhoFernandes har har hey hey
 
(Name sucks. I'm considering exclusive_ptr.)
 
What's exclusive?
 
The ownership.
 
12:33 AM
I have a body_ptr type and I can't help but read it 'body painter'.
 
lol
Can you specialise a class template with an alias template?
 
Uh maybe I should use p = nullptr; to stop that reset/release confusion.
 
template <typename> class foo {}; template <> using foo<int> = bar<int>;?
I think this warrants a question. (I'm feeling too lazy too look it up now.)
 
Well then I'm feeling too lazy to find an answer!
 
There are more people out there :)
Just in case your laziness ends:
0
Q: Can I specialize a class template with an alias template?

R. Martinho FernandesHere's a simple example: template <typename> class foo {}; template <> using foo<int> = bar; Is this allowed?

 
12:58 AM
Well, I found the answer.
No.
:(
 
What do you mean ":(", were you really expecting anything else?
 
Not really, but I think it'd be cool.
 
Neat, libstdc++ in debug mode asserts on std::unique_ptr<T>::operator*.
 
Anyway, I learned that alias templates are the aliases, and they don't have specializations (I'm using the correct meaning here).
@LucDanton For nullptr? That's cool.
 
For pointer() actually.
 
1:11 AM
I wish tuples had some syntax to easily make parameter packs out of them.
 
Good point! A TMP equivalent of std::forward_as_tuple/std::make_tuple. (That is not a metafunction with all the accompanying verbosity.)
 
Hmm, I can specialize variadic template parameters against <Head, Tail...> but I can't seem to be able to do it against <Init..., Last>. Is this a GCC limitation, or by design?
 
Design IIRC.
The other spot where template parameter packs have to appear last.
If Tail was a pack from an enclosing template you'd be able to though I think.
(Not that it does the same thing.)
 
Hmm, let's see how I can work around this easily.
 
1:50 AM
Man, SFINAEing can be so freaking verbose. void foo() enable_if(has_trait<T>::value) {} would be much better.
 
Boost.MPL has the right idea when it comes to metafunctions, too: void foo() enable_if(has_traits<T>);
 
@LucDanton uh, it can't do that
 
Oh, right, std::enable_if is boost::enable_if_c, correct?
 
@RMartinhoFernandes Yes.
 
@AlfPSteinbach I think he's adapting the hypothetical syntax I presented.
 
1:52 AM
@AlfPSteinbach What can't do what?
 
@RMartinhoFernandes oh
 
I think I'll just macro some verbosity away.
 
2:09 AM
@CaptainGiraffe I'm trying to make part of my application in C to interface with low-level system functions (the rest is in D), but the compilers use different object file formats so I can't mix them directly.
 
What compilers/platform, btw?
According to this digitalmars.com/d/2.0/faq.html#omf DMD produces ELF object files compatible with GCC on Linux, and Microsoft COFF import libraries can be converted to DMD object file format.
 
2:50 AM
hello?
if anyone's here
I was just wondering
 
I'm around.
Hi, btw.
 
Still hanging around.
 
if I have a class that relies on a certain member of another class
uh
how do you do that sytactically
wait
hold a sec
 
I think a small code example would help (if it's longer than a couple lines, post it on some pastebin like ideone.com).
 
nevermind
I'm just spent
lol
 
2:55 AM
Oh, you figured it out? Nice. It's been a while since I've fixed some problem with my presence alone.
:)
 
lol
 
I don't even know what I was thinking, the answer was blindingly obvious
thanks for your patience though
 
Arrrgh, I think I found one of those users that will incessantly rollback any and all of your edits to their posts.
 
there is always a first.
Can someone explain to me the difference between a socket and a port... jeez, they sound the same
 
socket is physical
port is virtual
 
3:00 AM
:O :S
Was that supposed to be a joke?
 
no
that's how I think of them
 
oh
right... how is socket any less virtual than port?
 
a joke: socket is for shoulder joint / port is for ships to arrive
 
lol i got that
 
3:01 AM
I just think socket is the actual physical thing with physical design specifications.
 
A port is a location (or part of the description for a location), a socket is a channel of communication.
 
like the pic
 
mmn I do't think it is
@RMartinhoFernandes lmao if only it was that simple
 
I'll just draw a line in the sand with this socket wrench
 
Sockets are opened and closed as communications come and go, ports don't "do" anything.
 
3:02 AM
what's the word that means the shape of the device?
 
Haha, the Code Review tag only has 74 questions.
 
@LucDanton why do ports not do anything
 
@ThunderRabbit Outline? (To follow the 'line in the sand' theme.)
 
hahah
 
If an IP address is a house address, a port is a room.
 
3:04 AM
yeah, but there's a word that means like the specification of the hardware
 
@LewsTherin That's a weird question. What do you expect them to do?
 
@RMartinhoFernandes oh right. I see
so the socket is the door to that room
 
@LucDanton I dunno hold data?
@RMartinhoFernandes mmn
 
0
Q: Is this low-level binding in the "C style?"

MaxpmI've prepared a small C interface so the rest of my program can access relevant system functions. I am not a C programmer, though - just C++ and D, mainly. I want to make sure that everything here is "C-ish" before committing the rest of my code to this interface. /* * This file provi...

Here's where you rail on me for not using ncurses.
 
3:06 AM
@LewsTherin I think you should pay more attention to the nature of things. (At least that works for me.)
 
A socket is a communication channel. A bit like a phone call (the call itself, not the phone).
 
Going back to the house metaphor, would sockets be like mailmen?
 
@RMartinhoFernandes right, so a call is the link between 2 end points
@LucDanton "nature of things?"
 
@Maxpm You shouldn't try to push metaphors too far.
 
@RMartinhoFernandes Perhaps not.
 
3:10 AM
oh
 
@LewsTherin In physics I don't add meters to watts because that's nonsensical. In their nature, length and power (which are measured by those units) are not similar things. So before you ask why ports don't do anything, I think you should consider if the nature of ports allow them to 'do' things.
 
is there any way to disable the windows-Alt codes when using pdcurses?
 
"Why doesn't a song do anything?"
"Why doesn't a thought do anything?"
 
@LucDanton they can both do things ;)
 
Songs can inspire people. Or relax them. Or rile them up.
:P
 
3:11 AM
exactly
xD
 
@LewsTherin No. (By 'song' I meant a work of art, not a musical performance.)
 
And a thought can make someone smile or drive them mad :(
 
@LewsTherin No, the person does that.
 
@LucDanton the person drives themselves mad? xD
 
Or 'they turn mad'.
 
3:14 AM
flee
so a socket is like a pipe. but what is this port? It makes a socket unique or something, but what is it?
 
Together with an address, a port defines an endpoint.
It's just an identifier.
 
so it isn't a memory address or something... it just makes a socket unique
 
a "socket" is just where apps "plug in" to communicate with the network. it's an api detail, not an actual part of tcp/ip. but perhaps that's being a bit too confusing at this point :)
 
Where have you registered obscure domain names?
 
@LewsTherin It does not make a socket unique.
 
3:19 AM
There was this site that had a decent GUI a while back with this obscure name that I can't find.
 
@LewsTherin When combined with an address, it makes an endpoint unique.
 
You use endpoint and socket as if they were different
 
They are.
 
I'm not playing this game. (time warped combo breaker!)
 
because they are.
 
3:20 AM
because they are
 
lol
what is the difference? God, help me
 
an endpoint is protocol-level stuff. "socket" is just an implementation concept -- an unnecessary one, at that, but the most common one.
 
From man socket: 'socket - create an endpoint for communication'. Talk about confusing.
 
heh
 
3:22 AM
Ooh, this is interesting. In "raw" mode, \n drops you to the character immediately below, not necessarily the line. \n\r does that.
 
i shouldn't have woken up from my sleep. thanks guys I'll try to understand it again
 
lol
 
\n is LF (line feed).
\r is CR (carriage return).
Does that help (I don't have high hopes)?
 
@Maxpm normally, it's \r\n (or \x0d\x0a)
 
goodbye
 
3:24 AM
later :)
 
@RMartinhoFernandes I know, but I find it a little weird that that's abstracted away by the terminal.
@cHao That's a bit unintuitive. But then, I haven't used a typewriter in a while. Did they return before jumping to new lines? I don't remember.
 
@Maxpm not sure. as for typewriters, carriage return almost always happened with a line feed. but either way, CR+LF is the line ending for most internet stuff
almost all, in fact. as well as windows and dos. frankly, *nix is doing it wrong. :)
 
@cHao Huh! And I always thought Windows was the weird one.
 
3:27 AM
It is, along with the Internet.
Being the majority does not make it right.
 
It makes it not-weird.
 
In fact, being the majority and wrong makes it even wronger :)
@Maxpm I don't know, I think a "new line character" is less weird than "two characters that when in sequence represent a new line".
 
@RMartinhoFernandes Maybe. At first glance, the separation makes sense to me, but I can't think of any instance where it might actually come in handy.
 
until you need the meaning of one or the other. for example, if you want to go back to the beginning of the line, or if you want to go down a line without necessarily starting at the beginning of the line
 
@Maxpm Electromechanical devices?
 
3:31 AM
@cHao Why would that be a character? Sounds like you're trying to control a device inline with the text.
 
and that is what control characters are made for.
why'd you think they were called that?
 
Which may have made sense at the time, but it's a tad silly now.
 
@cHao Right, but when would you actually want that? You can't do the former without potentially leaving stuff un-overwritten at the end of the line, and I don't know when the latter would even make sense.
 
oh? you mean, like, <Esc>[0j; ? :)
 
Phreaking should be a good example of why you want to separate your data from your control data.
 
3:33 AM
ANSI escape codes. <3
 
*nix has been doing crap like that for ages. every console emulates a terminal of some kind, which is controlled inline with the text.
 
But worry not, Unicode came to the rescue. It added not one, not two, not three, not four, but five more possible newline characters.
4
 
@RMartinhoFernandes It actually is a tad silly, isn't it? That's why I'm making a pseudo-library to abstract it away, I suppose.
@RMartinhoFernandes Wow, really?
 
Or just five.
And I have no idea if vertical tabs and form feeds didn't count as line ends before Unicode.
But it has a lot more shock value like that.
 
What the hell is a vertical tab?
 
3:37 AM
Another one of ASCII control characters that no one ever uses.
 
@Maxpm old stuff
 
That's ASCII?!
 
I must find a way to abuse this!
 
3:39 AM
heh
yeah, i've never seen a use for vertical tabs either. i've never even seen a vtab key. but old terminals allegedly had one
 
That's beautiful.
11
Q: What is a vertical tab?

dmazzoniWhat was the original historical use of the vertical tab character (\v in the C language, ASCII 11)? Did it ever have a key on a keyboard? How did someone generate it? Is there any language or system still in use today where the vertical tab character does something interesting and useful?

 
i think the worst problem with the ancient view of console windows as serial terminals, is that key repeat comes logically before key buffering. especially for delete keys. but also for arrow keys.
 
@AlfPSteinbach What do you mean?
 
@Maxpm e.g. if you have an unresponsive app, such as Firefox, and you press backspace to correct. uh, nothing happens. you hold it down to convince the "system" that you have pressed it. suddenly all the buffered auto-repeat keystrokes take effect.
 
@AlfPSteinbach I don't follow.
 
3:49 AM
try it
 
Make sure you get an unresponsive Firefox first.
:)
 
that shouldn't be too hard. :)
 
It works for me if I look at a large source file on bitbucket.
 
well it should be possible to try it with a little test program, just add in a delayh
 
You're saying that if I'm chatting here and my browser stops responding, if I hold the backspace key, more than one character of this text box will be deleted? Isn't that to be expected?
 
3:50 AM
yes, and no it's not to be expected
except for the effect of anachronistic technology
 
I'm trained to expect it now. It's too late.
 
i've always expected it, afaik
 
If I hold a key down for five seconds, I expect the program to handle five seconds' worth of characters eventually - even if it's frozen at the moment.
 
perhaps this is proof that people can be convinced to regard arbitrarily impractical designs as normal. as long as there's no alternative. anyway, for arrow keys, the old model means you have a very course-grained "resolution" of movement, and of course that you can't predict the destination when you have unresponsive app. it's idiotic.
 
I guess.
I'm just a youngster.
 
4:04 AM
truth be told, i can't think of a non-idiotic use for key repeat that would work better if it weren't buffered
 
@cHao well, to me it's just obvious that having control is better than not having control. like, repeat stops when you release the key. to me, it's idiotic design to have the repeats continue after you have released the key.
 
They do that?
 
They're buffered.
 
yeah. that's his point....the repeat logic happens before the buffering, so the repetition gets buffered
 
I think @Alf is advocating that key repeat only happens when the buffer is empty.
 
4:09 AM
@RMartinhoFernandes or just having the buffering before the repeat logic (of course for non-decoded keyboard).
 
do explain how this repeat-after-buffering would work...seems quite a bit more complicated
 
oh, the effect would probably be the same as with "only happens when buffer is empty"?
 
it'd be close
but not identical
 
@cHao do not go by appearances. there's a complete computer in your keyboard. with a little micro-controller. and one thing that this dedicated little embedded computer handles, is to generate auto-repeats. which the PC then buffers.
the other way around is MUCH simpler to implement
and it's also much simpler to use, giving the user control
 
hardly.
 
4:12 AM
@cHao "hardly" what?
i'm just relating the facts. they cannot be "hardly". facts are facts.
 
it's not simpler. i can easily picture how repeat-before-buffering works.
not the other way around.
explain how, or this "much simpler to implement" is bullshit
 
@cHao it's much simpler. i have implemented both schemes. i think your imagination must be deficient?
 
I could have sworn there was a signal for when the terminal is resized...
 
@AlfPSteinbach like i said. explain how, or it's bullshit
 
@cHao anyway, the original research on that was done in the late 1970's, as part of the Smalltalk project at Xerox PARC. they recommended non-decoded keyboard with timestamped keyboard messages (also timestamped mouse messages). you can read up on it.
i am not sure what you don't understand
 
4:16 AM
of course they would. smalltalkers love them some messages.
 
@cHao it was about timestamps, not messages. the low level keyboard interface in windows does give you timestamped messages. except that they're after buffering, which sort of negates the point.
that is, whoever designed that tried to do the same as something he or she had read or seen. but did not understand the point. and so messed it up, doing it backwards.
 
they did it that way because it's easier.
simpler.
it doesn't require timestamps and all that bs.
 
@cHao didn't you hear me? these messages are timestamped in windows.
this is the second time you're arguing with simple facts
 
in windows, they're timestamped.
 
i'm off
 
4:20 AM
at the keyboard controller level, and even at the bios level, it's a whole lot simpler than that.
 
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
 
yes.
saying it a hundred times doesn't make you any less wrong.
 
Whoa, calm down.
 
you are arguing with simple facts
i do not know how to respond to that
 
no, i'm arguing with your opinion.
unless your facts are wrong.
and you have yet to explain this alternative design.
which implies it's not even nearly as simple as you claim it is.
 
4:24 AM
what is it you don't understand about it?
let's start there
it is at the level of simple arithmetic, like someone stating they don't understand how 2+2 is 4
it makes it difficult to attempt any explanation
because it is down at the fundamental level where any explanation is more complex than the thing to be explained
 
He hasn't said he doesn't understand it, he's said he doesn't understand why it's simpler.
(Which would imply a level of understanding.)
 
i can see a way to do it, but it would be annoyingly more complicated.
you'd have to track key-down and key-up messages, and if the key-up happens soon enough, store it in the buffer...otherwise do the key-repeat logic, and only pass it along if the bufer isn't empty...etc etc.
on the other hand, repeat before buffering is simpler. if the key is held down long enough, keep producing key-down events. and any key-down event gets stored in the buffer.
 
oh ok. i see. you
are thinking way to complicated
what's buffered with a non-decoded keyboard, is the sequence of key up and key down events.
preferably with timestamps
 
by "non-decoded keyboard", you mean what, exactly?
that there's no repeat logic, buffering, etc at all?
 
it's standard terminology, and it means just that: that you get key down and key up events, with identification of keys, not identification of characters
it doesn't associate with any particular way of doing repeats
 
4:32 AM
that's what happens anyway -- the keyboard works with scan codes (keys), not chars. the bios and/or os is what does that translation
 
a decoded keyboard, on the other hand, gives you a stream of characters, sometimes escape codes. for example, a VT52 terminal, if you can get hold of one.
 
so, instead of the keyboard doing the translation to multiple key-downs, you depend on it to know what time it is.
 
@cHao no, usually the timestamps are added on the receiver end. i have not heard of any keyboard that itself adds timestamps.
 
Keyboard sends key events -> OS timestamps -> application deals as desired?
 
roughly yes
 
4:37 AM
doesn't that complicate the keyboard driver quite a bit?
 
what do you think could make the keyboard driver more complicated?
 
the fact that you can't rely on the repeat logic and buffering anymore, for starters. either the keyboard driver is always immediately available to handle keyboard interrupts and attach timestamps, or the timestamps are invalid
 
huh i'm sorry that's meaningless to me
i guess that whatever you have in mind depends on what you mean by "keyboard driver"
for example, with the USB keyboard I'm using right now, it doesn't get NumLock status until the Windows login screen appears
so that's a high level driver thing
 
the keyboard driver only gets the key-down and key-up events, right? no repeats?
 
with PC keyboard, as I recall the repeats are generated by the keyboard
so the driver would get repeats
but an auto-repeat can be easily identified at this level
and so it can just be discarded
 
4:44 AM
yeah, but you have major gripes with the standard pc keyboard. i'm talking about this alternative design you'd prefer
 
well the keyboard-generated auto-repeats can also be discarded at higher levels, so the basic driver does not even have to deal with that
 
meaning, you'd pretty much pretend they aren't there
 
yes
that's a good thing because the PC keyboard is limited to 31 repeats per second
which is rather slow
 
it's always been fast enough for me :) but eh
 
for the rational model of keyboard handling, new programs would however not deal with repeats as such, but instead deal with continued key-is-down
 
4:50 AM
programs don't care whether a key is down, though, they care whether a key is pressed.
 
currently, yes. dealing with key-down state for e.g. arrow keys, allows things such as accelerated movement. which you have today for mouse, but not for keyboard-driven movement'
 
whether it's released, or repeats, etc....doesn't care if they're just looking to get some text.
 
Or commands.
Like "move up", "move down".
 
but as i said, the basic research was done in the late 1970's. and so evidently the forces against scrapping the anachronistic technology, are very strong. maybe Apple could do it, but I think not Microsoft.
 
4:54 AM
apple wouldn't do it.
microsoft wouldn't even if they could.
which...truth be told, they could -- but it'd shift a lot of work away from the keyboard controller to the driver, and even to apps.
at that point, why have a keyboard controller?
 
it's part of layered architecture. lowest level deals with hardware. and so on.
 
but you don't get to say "lowest level deals with hardware", and then say "the os and apps should be handling key-repeat logic".
 
i do. but you don't. :-)
 

« first day (367 days earlier)      last day (4564 days later) »