« first day (453 days earlier)      last day (4478 days later) » 

Xeo
2:00 AM
But I somehow find a seperate immutable string nicer
Since you can copy that around and store it however you like
 
@Xeo Yeah, but it complicates APIs.
 
Xeo
With a string const&, you can't
 
Maybe that can be mitigated with implicit conversions.
 
Xeo
@RMartinhoFernandes How so? If you don't want to change the string, use an immutable_string (ugh, damn long name. Any better idea? ref_string?). And if you want to change it, use a string. They are convertible to each other
 
@Xeo A function that takes an immutable string should easily accept a mutable one as well.
 
Xeo
2:02 AM
@RMartinhoFernandes mutable -> immutable conversion.
 
1 min ago, by R. Martinho Fernandes
Maybe that can be mitigated with implicit conversions.
:)
 
@Xeo: So from your description you want to bring copy on write back?
 
Xeo
@Grizzly That's currently the only way I see that implementation working.
> At the same time, the mutable one needs to be able to convert to an immutable one and be able to detach its internals when its no longer needed, so the immutable string has the sole ownership.
@RMartinhoFernandes :P
 
Immutables don't need to know their data comes from a mutable one. That makes things simpler.
Oh, wait, they need.
Fuck.
 
Xeo
Yep
Because if the owning mutable one goes out of scope..
Well, it would work with a simple shared_ptr inside, I guess.
 
2:06 AM
I think it would be less problematic if creating a mutable string from an immutable always copies the contents (or steals it, if the immutable is a rvalue and doesn't share it's data with other instances)
 
Yeah, it's really a bunch regular COWs, except some won't ever copy.
 
Xeo
@Grizzly "However, to be able to actually efficiently interface mutable and immutable strings, the latter needs to be convertible to the former without immediatly causing a copy."
 
Only in PHP would you write switch(false).
 
Xeo
You can directly request a copied mutable string though: imm.str();.
 
Since you don't expect a call to void f(std::string const&); to do copies, you don't want void f(immutable_string); to do so either.
 
2:08 AM
@Xeo: yeah I read that, I'm just not convinced its a good idea
 
Xeo
(I would rather name the function mutable, but that's reserved...)
 
Xeo
lol
So it changes its aggregate state from solid to liquid, or what?
.phase()
 
It's the opposite of frozen().
 
Have buffer overflows been rendered redundant?
Sure. Today we have SQL injections and XSS, so overflows are pretty much redundant.
 
2:10 AM
mutable_string s = "blah";
immutable_string imm = s.frozen(); // implicit conversion also allowed
mutable_string mut = imm.thawed();
 
Xeo
I actually like that analogy
Or .solid() and .liquid()
 
freeze()/thaw() is common in objects that have "dynamic mutability".
 
@RMartinhoFernandes maybe .freeze() and .melt(). Function names should be verbs
Like "make shared"
or "pop"
 
@KerrekSB But it doesn't work in-place.
 
@RMartinhoFernandes Hm, I see.
 
2:13 AM
Ruby's convention of change (pure) and change! (in-place) is neater, but that doesn't work in C++ :(
 
Xeo
lol, I command thee to change!
 
Does someone have a good "You're doing it wrong" picture for my second comment?
@RMartinhoFernandes Ruby allows exclamabangs as function names?
 
@KerrekSB Yes.
 
@RMartinhoFernandes weird
 
Also ?s, which are used in predicates.
Like list.empty?
 
Xeo
2:16 AM
@RMartinhoFernandes Oh, and another reason for two distinct classes - only const member functions for the immutable one. :)
Since you can't have dynamic mutability in C++ without resorting to exceptions (which would suck hard, imho)
 
How does vector deal with non-POD data types?
In particular; how does it call the destructors?
 
@Xeo But you can! Just add dynamic mutability with UB instead of exceptions.
 
Xeo
Err, the same it deals with POD data types?
@RMartinhoFernandes lol
That would suck even harder xD
@IDWMaster ptr->~T()
pseudo destructor call
 
Wouldn't that fail if ptr doesn't happen to have a destructor?
 
Xeo
Huh?
Every object has a destructor
 
2:19 AM
Or ptr->T::~T() in MSVC :S
 
@IDWMaster Every object has a destructor
 
Xeo
@RMartinhoFernandes Wait...
 
Even fundamentals in that setting!
 
@Xeo It's a workaround for a bug.
 
Xeo
@KerrekSB "pseudo destructors". :)
@RMartinhoFernandes Does it actually change semantics?
 
2:20 AM
@Xeo "Does nothing, successfully".
 
Running valgrind on true gives me 523 allocs, 523 frees, 24,965 bytes allocated.
Same for false
At least no leaks.
I think I can do "nothing, successfully" with less effort.
 
Xeo
lol
523 allocs?
 
Let's codegolf "nothing, successfully" in C++. int main(){}, 12 strokes, I win.
 
@RMartinhoFernandes So you're saying even an int has a destructor, so this code should be valid
int* someint = new int(0);
	someint->~int();
 
2:22 AM
@Xeo Same for yes. Maybe it's some generic GNU preamble
@IDWMaster No, that isn't valid.
 
Xeo
@RMartinhoFernandes ret 1 byte, I win.
 
@IDWMaster Only when you have templates. You're allowed to pass a fundamental as a template parameter.
@Xeo Indeed!
 
@IDWMaster int doesn't have a destructor, but there's an exception to make template code that looks like ptr->~T() work.
 
@Xeo How big is your stack?
 
@Xeo Hey, that's not C++.
 
Xeo
2:24 AM
@KerrekSB Uh, why?
 
@KerrekSB At compile time, if the data type was an int, wouldn't it have the same problem, because T would be resolved to int?
 
Xeo
@RMartinhoFernandes Damn stealth edits
 
@IDWMaster No, there's an exception for that case.
 
@Xeo Maybe you can squeeze out a bit more performance by making all those data segments smaller
 
Xeo
@IDWMaster It's called a "pseudo destructor call"
 
2:25 AM
OK. I see.
Thanks!
 
Xeo
Aww, and I was just about to fire up my copy of N3290. :(
 
Xeo
Damn indexing bot
 
I never close the standard.
 
Xeo
I closed it some dozen minutes ago
Since I actually wanted to go to sleep
 
2:27 AM
Oh, me too. 3 hours ago :(
 
OK. Think this code to clear the array should work....
for(int32_t i = 0;i<length;i++) {
			data[i].~T();
		}
		GetAllocator()->unallocMem(data);
 
What's the type of data?
Depending on that you may want data[i].~T() instead.
 
Xeo
@RMartinhoFernandes Is that syntax even allowed?
 
Whoops
 
Xeo
I thought only ->~T(), and only on pointers
 
2:29 AM
@Xeo Yes, it is.
 
Xeo
k
 
foo f;
f.~foo();
::new(&f) foo;
// silly but valid
 
Xeo
@RMartinhoFernandes I'm awake since 10am yesterday after 3 hours of sleep. :|
Which goes another day back in a similar fashion
 
@Xeo Hehe, I think last time I woke up was yesterday about this time.
 
@RMartinhoFernandes Not silly at all. Sometimes you just want a fresh start.
 
2:31 AM
@KerrekSB It's dangerous. If the second ctor throws, UB.
 
Xeo
my_life I;
I.~my_life();
::new(&I) my_life;
 
@RMartinhoFernandes Why, because another destructor will be called?
 
Good point
 
Xeo
Btw, where can I access the bookmarks of this room?
 
2:33 AM
I.e. there might be no way out!
 
If foo had a flag always_throw_from_now_on, you'd be doomed
 
Xeo
@KerrekSB And what if the second destructor even throws!
lol
 
@Xeo That's a whole different nightmare
 
@Xeo You're already in UB-land by that time.
 
Xeo
2:34 AM
std::terminated
 
Hey, that's like a landmine
 
@Xeo No necessarily.
 
You step on it and hear the click, but you can't get up
maybe abort() would work
 
Xeo
exit()
 
Just to let you know, I'm taking a note that in this scenario, Hell++ will print a Lorem Ipsum instead of std::terminateing.
 
2:34 AM
Oh, yes
 
Xeo
Doesn't destroy any objects
 
That would make a nice interview question
 
Xeo
Formulate it, and post it on SO proper under the "as-if" rule
"as-if" you were actually asked such a question
 
Haha
Do you want the free rep?
 
2:36 AM
Rep for what?
 
@RMartinhoFernandes From the inevitable answer you'd post?
Or Xeo
This chat log is publicly visible on Google, though, so we might get found out
"Rigged questions"
 
Xeo
Then go for jeopardy style
 
Hey, I'm the guy that once asked to be a rep-bookie. My reputation (the non-numerical kind) is already ruined.
 
Hmm. How to fix this issue with placement-new c:/mingw/bin/../lib/gcc/mingw32/4.5.2/include/c++/bits/vector.tcc:295: multiple definition of `operator new(unsigned int, MemAllocator*)'
RefcountedObject.o:C:\Users\webadm\Desktop\SCHOOL computer\ModernPlusPlus\CoreTypes\Debug/..//mempool.h:148: first defined here
I need it for my mempool, but vector also needs it
 
2:41 AM
That sounds like you have a definition in the header.
Without inline.
Either make the definition inline, or move it out of the header into a cpp file.
 
@Xeo You mean formulate the answer as a question?
 
Xeo
@KerrekSB No, answer the question yourself
Then it won't directly count as "rigged question". :)
 
@Xeo I prefer C++ weakest link
 
@Xeo Community wiki?
 
2:43 AM
std::weak_ptr.
 
Xeo
No
 
@KerrekSB No, just ask and answer. That's actually encouraged.
 
You are the weakest pointer. Delete.
@RMartinhoFernandes OK, you can do it, because you pointed it out.
 
Xeo
xD
Chicken!
 
I don't want to.
 
2:44 AM
Interrophobia?
 
I don't think it's really worth sharing with the Internets.
Noobs might read it and get ideas.
 
I think the idea of landmining yourself is pretty cool
 
Xeo
I don't even know exactly which question we're talking about
 
@Xeo The destroy and reconstruct in place thing
 
Something about the "fresh start" trick.
 
Xeo
2:45 AM
Ah
 
I guess one could ask how to make that exception safe.
 
Oh, you can't CW a question
 
Xeo
Not directly
 
@RMartinhoFernandes But we already know that you can't.
 
Xeo
You can flag it, though, and ask for CW
 
2:46 AM
@KerrekSB Sshhh.
They might not know.
 
Xeo
foo f;
f.~foo();
for(bool constructed = false; !constructed; ){
  // brute force
  try{
    ::new (&f) foo;
  }catch(...){
    continue;
  }
  constructed = true;
}
Until it works, dammit!
 
@Xeo The landmine scenario :-)
 
I don't like limp for loops.
 
I'm looking for a catchy title. Something like "Can I get a fresh start..."
"... without failing?"
 
Xeo
"How can I get a fresh start in C++ without failing again?"
 
2:49 AM
"... without death?"
@Xeo OK, earmarked
I want something more personal, though
 
@Xeo: So is it exception safe, if it loops infinitely on exceptions?
 
I originally considered that abomination as a means to hack around non-assignable types. But then I gave up.
 
Since I'll be putting the exception thing into the question, I want to have a notion of doubt in the title
 
Assuming that if it throws once on construction its likely to throw again
 
Xeo
I think the "without failing" is good
 
2:50 AM
@Grizzly It provides the strong guarantee!
 
Xeo
@Grizzly Not if it waits on a volatile variable! :)
 
If an exception escapes, you have a guarantee no data was modified.
 
@Xeo: I didn't mean it will always happen every time, if it happens once, but it is a distinct possibility
 
Xeo
"How can I get a fresh start in C++ without stepping on landmines?"
Hmmm
 
foo::foo() {
    static bool nasty = true;
    if((nasty = !nasty))
        throw nasty;
}
 
Xeo
2:53 AM
We somehow need to incorporate the notion of "double destruction" into the title, and the safety notion
Nice
I think I'll actually post what I posted earlier as an answer xD
 
OK, who'll post the answer? I now made it sound like I really don't know.
 
You know, if I saw this question in the wild, I'd go and comment "Why the heck would you want to do this?"
Maybe I should do so, to avoid suspicion.
 
@RMartinhoFernandes Awesome
 
Xeo
Is it live?
 
@RMartinhoFernandes linky?
 
2:57 AM
0
Q: Can I get a fresh start in C++ without failing again?

Kerrek SBSometimes it's nice to start over. In C++ I can employ this following simple manoeuvre: { T x(31, Blue, false); x.~T(); // enough with the old x ::new (&x) T(22, Brown, true); // in with the new! // ... } But something tells me that it's not alway...

 
@KerrekSB I'm not posting the answer. I don't want to be linked to this abomination.
 
What is this? The grat placement new conspiracy?
 
@RMartinhoFernandes Lazy!
 
room topic changed to Lounge<C++>: Home of the Great Placement new Conspiracy [c++] [c++11] [c++-faq]
2
 
@RMartinhoFernandes If nobody answers this, I'll have to do it myself eventually, and then I'll CW it.
But don't let it come to that.
 
Xeo
3:00 AM
Don't worry, I sacrificed myself already
Damn that Karl Knechtel xD
Tell him that T is not assignable.
>_>
 
11 mins ago, by R. Martinho Fernandes
I originally considered that abomination as a means to hack around non-assignable types. But then I gave up.
 
Xeo
<_<
@RMartinhoFernandes That's why I said that
 
> Good question. (Even if it does seem a bit crazy). I think the placement new is OK. But I'm not so sure about the call to the destructor - it won't delete as much as you think it will. I'll experiment and write an answer. – Aaron McDaid 31 secs ago
Well, at least some good will come of this. Aaron is about to learn a bit more about destructors and placement new.
 
Xeo
lol, AzzA's comment xD
 
lol
"(...) most likely breasts (...) "
> It even provides the strong exception guarantee!
lol
 
Xeo
3:05 AM
This question actually attracts quite some attention xD
 
You know how it is with weird C++ corner cases.
 
Xeo
Well, anyways, hit 25k with that answer. :]
 
And the way it's formulated makes it somewhat clear that won't be used at home in production.
> Oh, T doesn't have an ass. operator
 
@Xeo Thanks, told!
 
@Kerrek Did you abbreviate on purpose?
 
Xeo
3:08 AM
@RMartinhoFernandes Never
 
@RMartinhoFernandes It's 3am, give me a break. Sometimes I get lazy
At least I didn't say that there was no T & ass. operator.
@Xeo: Can you make your post more whitespaced?
 
Xeo
@KerrekSB ?
 
Certainly seems like I start interesting discussions in here!
 
@Xeo Yeah, it's all cramped, with the egyptian braces and all
 
It's an honor that it even lead to the room topic being changed!
 
Xeo
3:10 AM
I like my egyptian braces, thank you. :(
 
@IDWMaster Quite! I had been doing this sort of in-place reconstruction before without ever thinking about the consequences.
 
Xeo
And it looks overly verbose without those
 
@Xeo At least put a space before the brace!
 
@KerrekSB You're serious?
 
Xeo
@KerrekSB Never!
 
3:12 AM
@RMartinhoFernandes Well, not in real code, but certainly on small test occasions. The landmine scenario never occurred to me...
and the fact that this may be one of the few ways in which you can really drive C++ into a corner
 
Xeo
That AzzA has good comments to boot
 
@Xeo: Maybe add that exit() is the only non-abortive way out
I mean, I seriously don't know of any other construction that you could feed with a maliciously prepared (but fully correct) class that would cause the program to freeze like that
Single threaded, say
 
Xeo
@KerrekSB will do
 
I've made programs before that have caused entire servers to freeze before
 
Xeo
it's in <stdlib.h>, right?
 
3:15 AM
@IDWMaster But where they completely correct C++?
@Xeo <cstdlib> I believe, and that's sir std::exit for you
 
@KerrekSB It depends on your definition of correct. If you mean they compile yes, but if you mean bug-free; obviously no.
 
Xeo
Edited.
 
I like cppreference. It has all the right information, provided it's complete
@IDWMaster Right. But this here has completely legit code
 
// now without limp for loops!
do {
    try {
        ::new (&x) T(22, Brown, true);
        break;
    } catch(...) {
        continue;
    }
} while(true);
 
Xeo
Oh, nice
Very nice!
no wait
no, yes
 
3:17 AM
I like my for loops three-legged.
 
Xeo
steals that
 
@RMartinhoFernandes Who's that different? Oh, one less local variable
 
Xeo
for(;;) would still be better
 
@Xeo Well, whatever is fashionable for a pseudo-infinite loop.
 
Crap, he also has egyptian braces. Ghrr.
 
Xeo
3:19 AM
unsigned _ = 1;
for(;_;){
  try{
    ::new (&x) T(22, Brown, true);
    break; // finally!
  }catch(...){
    continue; // until it works, dammit!
  }
}
I'm thinking of putting this in xD
 
lol
@KerrekSB But mine have force-fields that cause them to avoid contact with nearby tokens.
 
@RMartinhoFernandes Garrr - at least make the indent level 4 spaces!
 
Xeo
Ugh, 4 space indent!
 
@KerrekSB I did.
Modulo any counting mistakes on my behalf.
 
Xeo
Hell naw @RMartinho! I especially left it as non-const as to escape the compiler warning. :(
Maybe const-volatile..
 
3:21 AM
Oh, didn't consider that! Sorry. Better go with no-const no-volatile.
 
@RMartinhoFernandes No, not you, the other Xeo...
 
Xeo
const-volatile should escape compiler warnings, right?
 
Now that my new Array class is done, to write my Dictionary class (Array replaces vector, and Dictionary replaces map, yes, there is a very good reason why I'm not just using the built-in classes)
 
Red-black trees are painful.
 
@IDWMaster: Really? May I ask what it is?
 
3:24 AM
I'm writing a high-performance neural network/image analysis program
 
Xeo
#define _

int main(){
    for(;_;){}
}
hmmm xD
 
I need to use a highly optimized memory pool, and map, and vector are simply too slow, and it's easier to write a new vector and map rather than implement a standard allocator.
 
@Xeo Wait, isn't _ reserved?
 
Xeo
Yeah
sadly
That's why I won't edit it into the answer
 
But only on global scope, right?
 
Xeo
3:25 AM
Yep
leading underscore in global scope == reserved
Sadly, macros are always global scope. :(
maybe inside main with an #undef _ right after the loop? ...
 
@IDWMaster: It's easier to write new container classes then implement a standard allocator???
 
@Xeo It's still reserved.
 
Xeo
I know
 
@Grizzly Well, I couldn't get my allocator to work with the existing classes.
 
I'll threaten removing a watercraft if you put reserved names in your answer.
 
Xeo
3:28 AM
I don't!
See my comment
 
Wait, Johnsyweb suggests std::swaping with a new object.
 
Xeo
That's the same as assigning
Aka replacing yourself
while you only want a fresh start
 
@Xeo Not if swap is specialized.
 
Xeo
It's like replacing your brain and leaving your body
 
But yeah, on the metaphorical level, it's not the same.
 
3:29 AM
@RMartinhoFernandes Well, if we have no assigment operator, we probably don't have swap...
 
Xeo
I'm literally LMAO over the comments right now xD
Also, shouldn't that be "women as objects"?
Or was that intended?
 
@Xeo Plural of "woman" is "women".
 
the const volatile bool is really draining performance, though
 
Xeo
@RMartinhoFernandes Thanks, my mind is already tired.
 
Well, that was entertaining. I certainly learnt a fair share of valuable information.
 
Xeo
3:32 AM
@KerrekSB I'm facing compiler warnings without. :(
 
@Xeo Even without qualifiers?
 
Someone give Grizzly some votes for a neat use of noexcept...
 
Xeo
@RMartinhoFernandes Without const no
But you had to bring that in!
 
@Xeo I can't claim credit for that, it's from the Big Lebowski.
 
Xeo
Seriously, the comments are almost worthy a reddit thread.
> @Kerrek: hmmm... better than treating women like objects. But, I can see why you have to be worried about them throwing things.
 
3:34 AM
lol
 
@RMartinhoFernandes No. woman* isn't necessarily a series of women. It could be a pointer to a single woman, with no other women after it. Or are you talking about a vector<woman>?
 
Damn, I need to be awake in the morning.
I think I'll take a power nap around 7 o'clock and then sleep for real after lunch.
 
Xeo
@Kerrek, your question is already on the "hot questions" list
 
@Xeo It must be the distinctly non-programmy title
 
It's getting lots of activity, both in the form of jokes, and in good content.
 
Xeo
3:39 AM
62 views, 7 upvotes. That's a good quota
 
The view count is heavily cached. Don't trust it too much for such low values.
 
C# not C++, but you get the point.
That also had a very interesting title
 
What's the meaning of the number in the "hot" list?
 
Xeo
Some magic value
I never found out
 
3:44 AM
Post it on meta
We'll all upvote you, and get it popular too.
 
What number?
There's votes, answers, views, time posted, poster rep. No other numbers.
 
Xeo
"without the possibility of a hard failure?" - now I have a nice title! :)
@RMartinhoFernandes Top-left, dropdown box.
There are numbers in front of the posts
 
@RMartinhoFernandes No, in the menu on the top left
15
Q: How are "Hot" Questions Selected?

Robert CartainoI know "Hot" questions are based on some sort of views/velocity criteria but does anyone know the actual algorithm used? I was considering a feature suggestion about the "Hot" tab, but I don't have enough information to speak intelligently about it.

 
And I guess the number is the temperature.
In ºC because 29 ºF is damn cold.
 
3:51 AM
0
A: Can I get a fresh start in C++ without failing again?

AzzAI tried to compile it, but I only dared to run it under debugger. So I took a look at disassembly my old compiler generated (comments are compiler's too): @1 sub nerve.cells, fa0h @2 xor x, x // bitch. @3 mov out, x @4 test out, out @5 jne @1 @6 xor x, x // just in case. @7 sub money, 2B...

Haha, cmp new.one, %x
 
Xeo
Hm. I just noticed why COW sucks for std::strings - invalidation rules
You may cope with char* pointer + size_t index for a stable iterator, but references will be invalidated when unsharing the string. :(
mutable_string const const_string = "hello"_s; // imagine this is a parameter
char const* p = &const_string[0]; // no unsharing
// something outside unshares the string and changes [1] to 'a'
assert(*(p+1) == 'e'); // boom
 
You need to unshackle yourself from the std::string interface.
 
Oh, typeid can throw an exception?
 
Xeo
Yeah, for 0 argument
when dereferencing
typeid(true? *p : *p) circuimvents it, interestingly.
@RMartinhoFernandes But, that still sucks. :/
 
4:05 AM
COW doesn't work well with that interface. The sooner you accept that, the sooner you can design one that works well.
 
Xeo
It still sucks that you can't safely store a reference into the string
Anyways, I'm off to sleep for now. Gotta get at least some... until I'm brutaly woken up again to babysit my little brother like yesterday.. :|
 
Now that you mention it I really should go to sleep too
 
I guess I'm going to doze off a bit too. Good night.
 
good night
 
4:24 AM
Good evening everyone..
I have a quick questions regarding Macros in c++ if anyone can help?
Shall i state the question?
 
user406009
Don't ask to ask
 
user406009
Just ask
 

« first day (453 days earlier)      last day (4478 days later) »