« first day (713 days earlier)      last day (4463 days later) » 

00:00
Yeah but I'm pretty sure there are guarantees to substitute the previous incantation with static_cast<T*>(static_cast<void*>(this)).
Duh! Winning!
0
A: How can I print out the contents of std::stack and return it's size?

Cheers and hth. - AlfBoth std::stack and std::queue are wrappers around a general container. That container is accessible as the protected member c. Using c you can gain efficient access to the elements; otherwise, you can just copy the stack or queue and destructively access the elements of the copy. Example of usi...

^ He he
I'd say put the storage as the first non-static data member, only use one access specifier for all non-static data member?
@Xeo Get a more picky browser. Your browser will just follow malformed links :0
@chipperyman573 We didn't know that. Also, what did you expect to improve on, then? :) The web request is the thing that takes the time... — sehe 2 mins ago
^ fools
Xeo
Xeo
@sehe There simply are no tripple slashes for me in that link
00:04
Is it mean or wrong of me to think these people are idiots? Or have I just forgotten that I may have been so dumb was I started programming?
Xeo
Xeo
Is what I get when I do "copy link location"
@Chimera most people are idiots. proof: almost no american would vote for an openly rational (atheist) presidential candidate
Because atheists are pricks.
@R.MartinhoFernandes I have to tell you that researching this took me way too much time. The rules for pointer conversions are not very explicit.
but they would vote for a catholic one (e.g. consider their record re contraceptives, child abuse, etc., and cannibalistic rituals)
Xeo
Xeo
00:06
Why not simply contain a pointer in your optional?
@R.MartinhoFernandes well i'm an atheist
:)
You're a prick!
:P
@Xeo That's what the robot does (used to?). Think of optional<int> though.
I don't take into account a candidates religion. Period.
Xeo
Xeo
00:06
@LucDanton Well, don't you need to indicate whether that thing is initialized anyways?
@LucDanton A pointer? That's off-site storage!
@Xeo Ya. You're right, it's not too bad.
Xeo
Xeo
And you get padding to nearest word anyways, IIRC
Oh, instead of the boolean?
@Chimera my religion compels me to fart loudly in full elevators. it's the "elevated fart" religion
00:08
@Xeo I code against C++.
Emphasis on against.
Xeo
Xeo
heh
I am looking at one of the now deprecated homework questions and it is wrong for so many reasons but the question is marginally good enough: stackoverflow.com/questions/476576/…
@Cheersandhth.-Alf :-)
Xeo
Xeo
00:08
And for variant, you could store a void* that is casted, right?
@Xeo Not after your browser fixes is to allow navigation to it. Check with Chrome's 'Inspect element', other browser's hover status bar or ... just the history: chat.stackoverflow.com/messages/5542120/history. Clearly, three slashes in http:/// :)
Xeo
Xeo
Instead of casting over void* from the storage
I thought that much, yes. Have yet to go through with it.
Well no, I'm going with this. But as a fallback.
Xeo
Xeo
@sehe Pff, I've been set up!
@HaskellElephant Duly noted. Good enough for... laughs? jokes? What?
00:10
This is kinda silly.
It's like "you have to jump through hoops", basically.
@Xeo Just early signs of Parkinson, nothing out of the ordinary ;)
But we won't tell you what hoops.
@Cheersandhth.-Alf star bait fail
@sehe the whole thing is weird. (By good enough I mean: good enough to not be voted as too localized I guess) The problem is that the answers are not to the question asked and of course vague...
Ok, time to sleep.
Xeo
Xeo
00:12
Same
g'night
@sehe but definitely good enough for laughs )D.
Bad title / good title? Stack overflow. Bad title is like "Bad title / good title" stuff like that — sehe 10 secs ago
^ This is better for laughs
-1
Q: Bad input / good input? C Programming. Bad input is like "*, . " stuff like that

user1698484int main (void) { int yearEntered; printf("Enter a year: "); scanf("%d", &yearEntered); int read = scanf("%d", &yearEntered); if (read == 0 ) { printf("Bad input: requires an integer"); } else if (yearEntered%4==0 && yearEntered%100!=0 ||...

@MooingDuck Congratulations, man. Sorry I'm so late on the takeup.
^ just for archival of the amaaaaizing title
@sehe nice one ...
@sehe You might not believe it is the middle of the night here and I am actually laughing out loud here...
00:17
@HaskellElephant it's 2:17am here. I'm laughing :)
@sehe same time here...
Man. It's the twilight of bizarre titles:
<troll>The symbol Errro is not found. Probably because it was misspelled (did you want to type Error?)</troll> — sehe 23 secs ago
00:32
Well since everybody seems to have gone take naps, I'll just do the same.
@sehe For a task this simple, it is hard to come up with anything different, let alone essentially different. The only difference is referencing string.Empty explicitly, and the OP requested a return of string.Empty. — dasblinkenlight 56 secs ago
Why do people answer if they know the question has no useful answer the OP doesn't already show? ^^
In this case, obviously, even the 'solution' shown by the OP isn't very useful...
Where are all the questions?
@sehe huh which case
oh
@Cheersandhth.-Alf :)
I ate them. Sorry.
<burp/>
Night all :)
00:49
I have a quick question
someone told me that I can implement the hash_map class in a C file
how is that even possible?
@febreezey you can call a file whatever you want
i'm not sure what you mean
like if i were writing a standard C file and I wanted to use C++'s hash_map class, is it possible?
you can name the file [bonkarakka-whacka-schlacka.pascal] if you want
that is, with a [.pascal] filename extension
no problem
if i'm using the g++ compiler it doesn't matter?
@febreezey Probably not. But I'm not sure I understand what you're asking.
01:01
it matters a little bit for the tool usage
like let's say i'm writing a tcp client/server application and i want to store stuff the user inputs in a hash table
but i like hash_map in C++
how do I set myself up to use it?
also, in order to not confuse others it's better to use well-know filename extensions for c++, like [.cpp], or [.cc], or [.cxx]
or [.hpp], or [.hxx]
hm, more?
@febreezey simply do the coding in C++
easy as pie
this is technically for an assignment and they want it in C
After you've implemented whatever it is you need in C++ you can expose bits of it to C.
(That is to say, anything that can understand C would be then able to use it. Like C programs.)
write the C++ stuff and then just #include it in the C file?
01:04
@febreezey It doesn't sound very much honest to use C++ if C was asked of you, but maybe I didn't get that requirement right.
nah, the client and server are going to be in C, but the data structure to hold stuff can be whatever will work
and hash_map works well with multiple keys having multiple values
Okay. The usual approach is to write a polyglot header. That is to say, a header that is a valid C file, and a valid C++ file.
i'm not sure i've ever heard of that before
I'm writing a demo.
@febreezey This is what such a header may look like.
You have to be careful though, you can only write code that is correct C and correct C++ in such a header
ahh i see, so all of my hash_map stuff goes in there?
and what is the PUT_INCLUDE_GUARD_NAME_HERE mean?
01:11
No all of it, only what the C-speaking world must see to use your code.
@febreezey You may want to look up what an include guard is.
oh never mind, i know what that is
and in that case, i'll have a separate C++ file somewhere that includes that polyglot header as well?
Indeed.
This assumes that you will be writing a library though.
If what you want to write is one big program then I wouldn't advise doing it that way.
all i really need is a hashmap, will this be sufficient?
Maybe.
Are you part of a team that is writing a program with C? If so, writing parts of it with C++ is a bit icky. Don't do it unless you know what you are doing.
No i'm alone, and yeah I know. I'm not a guru at C++
01:15
@febreezey you will need to use C++ for main. just let it call a C main function if you want mostly self-contained C code.
01:27
I have a struct with several int and pointer types, and a destructor. Is there a way to get it to initialize all variables to zero when I do new Foobar()?
I read something that implied that MSVC++ doesn't handle that case properly, and does not initialize.
That's what I'm using btw.
Is adding a default constructor an option?
Well, yes, but I think that would require me to specify initialization for every member.
Which looks ugly to me.
Not much of a choice, although you should check for yourself that your compiler really botches that, because it would be non-conforming.
By which I mean new Foobar() is supposed to do what you want.
Well, when I look at the memory where the struct is created, it 's uninitialized.
@KendallFrey you're already specifying zero-initialization (or rather, value-initialization) by having the argument parenthesis
01:32
Problem is, I don't think MSVC++ behaves right.
@KendallFrey which version of msvc. as i recall it hasn't been a problem since 6.0
I'm using 2012 Express.
that's ok version
well, except you can only create metro apps with that
:-(
I'd be surprised if such a bug would be present. It would be a huge flaw.
Um, not the desktop version.
01:33
have they released that now?
where?
Somewhere. The official release is out.
Anyway, this is what my struct is initialized to:
cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd
@KendallFrey i can't say i believe you
Try to replicate the behaviour in a small program. Easier to submit a bug.
Unless there is a problem with my struct declaration.
oh sorry, it's there
nobody's said anything!
01:37
Eric Lippert blogged about it, so we got notified in the C# room :)
i knew it would be coming, but i never heard they had released it
it was not released along with full product
typedef struct Foobar
{
	int foo;
	int baz;
	int steve;
	int pink;
	Hello *boo;
	int snark;
	int fleer;
	Hello *zank;

	~Foobar()
	{
		delete[] boo;
		delete[] zank;
	}
}
Foobar;
See any issues?
what's the typedef for. silly.
you don't have destructors in C
so you can't use that in C
waitasec. you don't need them in C++?
01:40
#n00b
face <--- palm
@KendallFrey There's a problem in relation with the rule of three.
What is that again?
One the one hand, this has nothing to do with new Foobar(), on the other hand, it can easily lead to bad things.
229
Q: What is The Rule of Three?

FredOverflowWhat does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?

If you provide a destructor, you should in all likeliness provide a copy constructor and a copy assignment operator as well. (This is C++03 advice.)
Hmmm
AFAIK, no copying will take place.
So I should be fine without it.
But I maybe should implement them anyway.
#include <iostream>     // std::wcout, std::endl
using namespace std;


struct Hello {};

struct Foobar_state
{
	int foo;
	int baz;
	int steve;
	int pink;
	Hello *boo;
	int snark;
	int fleer;
	Hello *zank;
};

struct Foobar
    : Foobar_state
{
    Foobar(): Foobar_state() {}

	~Foobar()
	{
		delete[] boo;
		delete[] zank;
	}
};

int main()
{
    Foobar* p = new Foobar();
    cout << p->foo << endl;
}
01:44
In that case you can declare a private copy constructor with no implementation. This counts as providing a copy constructor.
I think maybe that value initialization may not apply when you have a destructor.
But the above code takes charge.
I can't resist the urge to say, "ew."
right
you should not have raw arrays there
use std::vector
the wrapper seems really unnecessary
it is unnecessary when you do things properly, like using std::vector
01:46
Oh boy, 8.5 here we go again.
I guess I shied away from it because most of my experience is with C.
> if T is a (possibly cv-qualified) non-union class type without a user-provided constructor, then the object is zero-initialized and, if T’s implicitly-declared default constructor is non-trivial, that constructor is called.
I do need pointers to pass to external code though.
But that shouldn't be a problem?
> An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized.
Now to cross-reference with C++03, ugh.
Anyone ever tried to throw a boost::variant of rudimentary types in to shared memory?
not throw as in throw()...
01:52
@Cheersandhth.-Alf I'm not under the impression that this is a factor tbh.
@jvstech Well, that's a relief. But what are you trying to do?
Sounds like you're really looking for a serialization solution, on the surface of it.
heheh. I've got a boost:variant<int, long, double, SharedString>
as the value type of a boost ipc map. This map is accessible by other processes and provides configuration info.
I would normally just write this stuff to a plain old flat file, but permissions (in this case) prevent that from happening.
SharedString is a shared-memory-safe string if that wasn't obvious
Yep… serialization. One could use a stringstream<SharedString> or similar buffer with the same format as the supposed, desired file.
Having pseudo file formats floating around can get ugly.
There's a templated version of stringstream?
I don't even know what I don't know.
std::basic_stringstream. All of iostreams is templated but many of the templates are a bit useless.
01:58
Ahh. So std::basic_stringstream<SharedString>
And then SharedString has to have an appropriate interface compatible with std::string.
SharedString is basic_string with a custom char allocator for shared memory
Well then you should be in good shape. Maybe.
Always a maybe.
@jvstech Not likely to work. To give you an idea std::stringstream is an alias of std::basic_stringstream<char>.
02:00
Well, std::basic_stringstream< char, char_traits >, and I think C++11 adds an allocator.
I'm not wrong.
Yep.
template <class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT> >
Ah. I'm not using a C++11 compatible compiler.
No way around that.
vector<Hello> boo;
02:02
Policy. It sucks.
Am I incredibly stupid?
That doesn't work.
@Potatoswatter The allocator is present in C++03 as well.
syntax error : missing ';' before '<'
Well then I should be good, yeah? I can just use my SharedCharAllocator
@LucDanton Oh, really? Anyway, as an extension it was still standard compliant with C++03.
According to cppreference the allocator is new in C++11: en.cppreference.com/w/cpp/io/basic_stringstream
02:04
I'm just gonna use the boost ipc map with SharedStrings for both. lexical_casts for everybody.
I'm not looking it up, just got to the office and need to get down to work.
I've been working on this for two days and too stressed to write any code for it.
Yeah, if it aint broke don't fix it…
That's not our policy at work. If it ain't broke, break it.
But you know that structured shared memory is a security hazard.
02:05
And then force everyone to use it and tell them its for their own good.
Yep. This is on an airgapped network.
@Potatoswatter Get out of here. My reference is 27.7.4 Class templatebasic_stringstream [lib.stringstream].
Sorry for being such an idiot n00b, but...
HELP MEEEEEeeeeee.......
@LucDanton I gotta get to work. You fix cppreference.com if you want.
@KendallFrey Cannot reproduce. What do you expect us to do exactly, engage our psychic powers to read your code?
02:07
Your error is on line 42.
#pragma once

#include <vector>
#include "hello.h"

struct Foobar
{
	int foo;
	int baz;
	int steve;
	int pink;
	vector<Hello> boo;
	int snark;
	int fleer;
	vector<Hello> zank;
};
Should be std::vector.
Goddammit!
using namespace std;
or more preferrably (maybe) using std::vector;
as other options, I mean... I always use the std:: namespace prefix.
FML, and I hate MS's 'C++' compiler.
Oh, and why use std:: every time?
seems like a waste of typing to me.
02:11
more verbose when looking at the code
I'm using 2 libraries plus std:: and putting my own stuff in another namespace.
an indication to my other team members that I did not, in fact, write this vector or string or pair class
(Finally my work is back to C++! Hooray!)
I use C# most of the time. I can't stand specifying a namespace for a type.
I don't do it in C#.
02:12
@KendallFrey It depends what you mean by 'every' time. At some point, it has to be made clear which vector identifier you really want. Maybe that point is a type synonym.
Just C++.
@LucDanton well i haven't checked but if it isn't then we're talking compiler bug here
@Cheersandhth.-Alf Yes. This would be less likely than me misreading the C++03 Standard.
I know everyone told me to YAGNI about the exportable template types, but I managed to get it compiling and running from a DLL. So I'm fairly happy about that.
Good thing I'm not actually working on anyone's dime. I'd be a project manager's worst nightmare. :3c
Speaking of which, thiis may be extremely specific, but how is a windows fastcgi application supposed to be written as a DLL compared to an EXE?
02:15
I don't even know what fastcgi is. Google time!
Does everything just execute inside Dllmain?
I tried looking for the answer, but it was just a cursory search...
Maybe it expects the user of the DLL to call critical functions or service certain functions in their main loop?
No clue. Maybe I should just read the fastcgi documentation...
RIP, Homework.
02:18
^ It's worth repeating, the PHP tag is also pejorative!
Though I don't mind that the Stigma associated with "YOU ASKED A HOMEWORK QUESTION WTF" being swiped off either.
I mean, the amount of flame that seemed to be demanded the minute the Homework tag was involved in anything made me never want to ask a homework-related question on SO ever.
[tag:like-this]
I think the space you had in there screwed it up @Cheersandhth.-Alf
02:20
Thanks guys, I've got my issue seemingly fixed!
@KendallFrey thanks, no spaces, right
So long, and thanks for all the fish!
02:33
i conclude that i don't like liars
What is your evidence to support this conclusion?
many years back, i just pointed when people lied -- really pointed at it, showing where the person clearly knew X, and where the person maintained not X -- and said hey, you're lying
but then that came back to bite me in a discussion with some, well, liars
so i stopped doing that, but now i regret that i stopped
And that evokes discomfort?
it invokes a decision to change. for the worse, as most SO denizens will perceive it.
Peer review complete. All points valid.
 
2 hours later…
04:21
Well, for what little it's worth, I'm back from the Denver SO grand opening. I forgot my camera, so I don't have any pictures, but @shog9 took a quick shot of the two of us together, so perhaps he'll post that.
2
 
1 hour later…
05:32
@LucDanton how does one register with LWS?
@Cheersandhth.-Alf No idea, never tried.
so, how did you get file-specific URL to source code then?
i see no menu choice for that
no button
like
oh, just compile
It might as well be magic to my eyes.
^ Works more or less (apparently sometimes less)
no compilation
06:31
@KendallFrey You're welcome
@JerryCoffin Nice... SO IRL HKAT?
@Cheersandhth.-Alf I tried, it is just not possible. Probably future feature or admin backdoor
sbi
sbi
@KendallFrey See this.
Bottom line (from here): A line of code gets written once, but - depending on its lifetime - it is read tens, hundreds, and some even thousands of times. So the time it takes to write a line of code simply doesn't matter at all, important is only the time it takes to read and interpret a line of code.
06:49
@sbi As a guy who often does maintenance/enhancement, and too often finds the 'docs' folder empty, I can only agree wholeheartedly. Macros, unnecessary operator overloads, over-complex one-liners etc. make my life very difficult.
07:11
@TonyTheLion Le Stroustrup proposal?
07:37
@sehe Seems like
mornin'
why is it so quiet in here?
I have a method that writes data to a wchar_t buffer and returns the number of bytes written to that buffer. I'm passing &std::wstring[0] there as the buffer. If after that function returns I'd use std::wstring.resize(returned_size) will std::wstring keep the extra null character in the buffer? or I need to do std::wstring.resize(returned_size + 1) ?
that's too short for a full-blown so question :)
@KarimA. So post a short question, not a full-blown question. Post code that compiles & it will be longer.
07:43
@KarimA. If returned_size is the number of bytes, shouldn't the argument to resize be returned_size / sizeof(wchar_t)?
msdn.microsoft.com/en-us/library/windows/desktop/… the returned value is "the length of the string that is copied to the buffer, not including the terminating null character".
> the return value is the length of the string that is copied to the buffer, in characters, not including the terminating null character.
Since the size does not include the null character, then the resize operation would truncate it.
That being said, s[s.size()] is a null character, always. Similarly for s.data()[s.size()] or s.c_str()[s.size()] (not sure about the exact C++03 guarantees though).
okey, no pron yet. If I ever come to this chat in US time, kick me
07:50
lol
Ah, C++03 doesn't give the guarantee for the result of s.data(). It's fine for s.c_str() though. This should help pick a choice for your resize operation then!
Thanks Luc Danton!
I'm serious. I didn't realize what kind of creature Drise is, and when I did, it was too late
Also, another question along the lines: is there any guarantee in c++ that std::string is allocated on contiguous memory like std::vector?
07:52
I thought we'd got over that
Because I'm wondering if it is always safe to use it this way.
@KarimA. in C++11 there is such a guarantee I believe
> . The string spec was also tightened up in C++11 such that it is required to be contiguous
16
Q: Why are std::vector::data and std::string::data different?

deft_codeVector's new method data() provides a const and non-const version. However string's data() method only provides a const version. I think they changed the wording about std::string so that the chars are now required to be contiguous (like std::vector). Was std::string::data just missed? Or is th...

@KarimA. from here ^
@KarimA. what do you mean "this way". You shouldn't be using a class in other way than it allows you
@BartekBanachewicz - both allow this usage.
@KarimA. both allow operator[] and iterators. I don't see how it's related to contiguous memory
07:55
@LuchianGrigore Shhh! Don't wake the developers!
@Bartek, Both allow taking the address of their first element and the question was if &[0] -> &[0 + size() -1] is contiguous and could be treated as an array.
@KarimA. Why would you want to use something as cruel and painful as &[0]?
I need to call a Win32 function that stores a path in a user-allocated buffer.
okey, win32. that's ok excuse for me

« first day (713 days earlier)      last day (4463 days later) »