« first day (669 days earlier)      last day (4279 days later) » 

10:00 AM
but IIRC cout is not a class, it is a global instance
 
yeah
it's a specialized std::ostream of sorts.
 
indeed
 
so existing ostream overloads should be ok for the new thing.
 
@NeelBasu so in conclusion, yes it could be done, but it's not going to be a simple task :P
 
nor is it useful or good design. Although that opinion is controversial.
 
10:03 AM
indeed, I would avoid mixing char and wchar
 
@thecoshman so this won't work?
1
A: generic cout that can be wcout depending upon typedef

ecatmurYes, no problem; you can do this with a template specialisation holding a static reference to the appropriate object. template<typename T> struct select_cout; template<> struct select_cout<char> { static std::ostream &cout; }; std::ostream &select_cout<char>::cou...

 
hmm... I guess you could do something like that...
 
it's not enough to "support unicode" at all.
 
@ecatmur well, as far as I can tell, that still requires you to know at compile time if you are using char or wchar, thus is pointless
other then perhaps saving you a little bit of time
 
@R.MartinhoFernandes starting a sentence with 'and' is bad practice
 
HMODULE is a handle to a loaded DLL or executable image (collectively known as modules). It must be closed by passing it to the CloseHandle function - bullshit
 
Oh, don't give me that stupid crap.
@Abyx What is wrong?
 
CloseHandle closes HANDLEs, not HMODULEs
 
CloseHandle closes a lot of things
 
10:21 AM
also you can't "close module", you can only free it (via FreeLibrary)
 
@Abyx Dammit. Thanks.
They lied to me!
 
@R.MartinhoFernandes gonna read it now at rmartinho.github.com/2012/08/15/rule-of-zero.html (I presume you published it without my consent :) hahaha)
 
also modules are reference-counted, so you can copy objects with HMODULE if you'll increment reference counter by calling LoadLibrary. (however I've never seen in IRL)
 
@Abyx Yeah, I figured that, but that would require saving the name and make the example a bit bigger.
@Abyx I think I've fixed it. Thanks again. I was led to believe that CloseHandle could close any kind of kernel object. If I only had checked the docs I would have seen that was not true :S hides in shame
 
@R.MartinhoFernandes init 6
 
10:32 AM
@sehe Yeah, I thought it was free from major mistakes. I suck.
 
@R.MartinhoFernandes Well, I lied. A bit. Not reading it yet. Looking for a linux A2DP (bluetooth hifi audio client).
 
It's okay. That won't disappear anytime soon.
 
oh, I got the yearling badge yesterday
 
is it possible to build a collection of lambdas?
 
With std::function.
 
10:39 AM
derp
std::vector<std::function> sheep; sheep.push_back([](){}); right?
 
yep
 
Well, with an actual signature argument for std::function.
 
lol, I didn't noticed that
 
@R.MartinhoFernandes did I mention derp at any stage :P
 
10:51 AM
pointless use of lambdas - I am sure I will find a valid use for something like this at some stage...
 
hm... I have a static library which is compiled with _MBCS, and an application which uses it, compiled with _UNICODE (MSVC2008). The library calls ::GetCommandLine(), and somehow it's GetCommandLineW which is being called. It's fucking strange... seems to be a LTCG magic
 
is []()->{} a valid lambda? or would you have to add a return type after the ->?
 
Needs a return type.
 
will it not assume void?
 
10:59 AM
but with [](){} it does deduce void return type, right?
 
Is is possible that lambda is slower than inlinable function object?
 
rage cat
 
@StackedCrooked Only on a silly compiler: a lambda is an inlinable function object.
 
11:03 AM
@R.MartinhoFernandes Hm, I'm not sure if I noticed the slowdown on gcc 4.5 or gcc 4.6. Anyway using 4.7 at home so I could test myself.
Suppose I have a big class hierachy without any virtual methods. If I were to make the root class destructor virtual, would that add vtable entries to all derived types as well?
Or will only the root class be affected?
 
Each derived classes will have its own vtable.
 
I see.
So I assume each derived class will need to lookup it's destructor before calling it.
 
Yes. Kinda sucks if it does nothing, but there's little that can be done to alleviate that.
 
Any haskell fanboys here ?
 
Nah. We love C++
 
11:15 AM
Cat is probably asleep.
 
snap.
 
We're trolling. Most everyone is a Haskell fanboy here
 
> Size matters -- The Robot
Haha
 
I have a haskell problem and I can't even properly explain what it is
 
11:16 AM
@sehe What about it?
 
Funny comment
@kbok There is no spoon
 
@sehe ?
 
@kbok Well. There isn't. If you can't explain, there isn't a problem :)
 
@kbok I might be able to help, then.
@sehe You linked to a diff of a picture.
 
@sehe I think the problem is that I can't explain :)
 
11:18 AM
He's psychic. And pointless pointfree
 
@R.MartinhoFernandes I use the Get monad to read binary data from a file
 
I assumed that the commit message referred to that diff.
Also, unrelated: nifty that github shows side-by-side image difffs
 
I have a function which constructs a list of ByteStrings
Apparently its type is [ByteString] but the compiler wants it to be Get [ByteString]
Also I'm not sure if I'm doing it the right way.
 
@kbok So you have something like Filename -> [ByteString]?
 
In the end yes
actually:
readNames :: Int -> Get [ByteString]

readHeader :: Get [ByteString]
readHeader = do readNames 20

main :: IO ()
main = do
	print $ runGet readHeader
I stripped the code from irrelevant bits
 
11:27 AM
Can you tell me where this Get comes from? From the name it looks like Reader, but I don't remember ever seeing Get.
 
is there any operator+ overload between wstring and string ?
 
@kbok Ah cool. You won't be able to open a file inside readNames like this.
 
@R.MartinhoFernandes Yes, the file is opened in main (here it's stdin since I don't specify a filename)
 
Hmm, then what is the problem? You want readNames to be Int -> [ByteString]?
 
11:30 AM
I want readNames to be Int -> Get [ByteString] but it's Int -> [ByteString]
I tried :
 
readNames 0 = do return []
readNames n = do return getByteString 50 : readNames (n - 1)
 
@R.MartinhoFernandes Whew. I made it to the end :)
Minor detail: Let me guess you're on Chrome (since FF, Opera have issues displaying the bulleted list - looks like a CSS issue)
 
The second equation looks like it should be = do { head <- getByteString 50; tail <- readNames (n - 1); return (head:tail) } (or something with a lifting function if you prefer).
 
@R.MartinhoFernandes Why is it different ?
 
11:33 AM
getByteString 50 : readNames (n - 1) has type [Get ByteString].
 
@R.MartinhoFernandes On the whole, I thought it was a bit 'wordy' compared to other posts. I like your more terse style more, I think. This was the first post I ever had the TL;DR reflex with.
 
You want to extract the values from each part and cons the values, not the monads.
 
Have you considered starting with the - awesome - soundbyte/definition that trails at the end of the article?
 
@sehe I'll check that out later.
 
@R.MartinhoFernandes I tried it actually, but the results seems to be the same
 
11:35 AM
@sehe That does sound nice.
@kbok Lemme fire up an interpreter.
 
11:49 AM
@R.MartinhoFernandes I'll leave you for now - you seem busy juggling chat threads :)
 
@R.MartinhoFernandes That reminds me that I should try clint.
 
@R.MartinhoFernandes If you want I could propose some edits where I think 'verbiage' could be cut down while increasing clarity. (I do really love how you achieve the clarity, while still reaching the necessary details)
 
@sehe Sure, that'd be welcome.
 
I'm starting to like Spotify - unexpectedly.
My ISP ran an offer (year-long free premium Spotify subscription). I dismissed it, because, well (a) I have my own music (b) I'm a HiFi addict (c) My experience with internet music sources is: it sucks for non-pop
 
The plot is swelling.
 
11:56 AM
How different Spotify is turning out. I can still detract a few points on the - suboptimal support for metadata on classical albums. But the availability of music is... astounding
Add to that my HTC phone, the Spotify APP and a Bluetooth A2DP audio receiver... it is really starting to capture me.
 
A basic bluetooth receiver costs $5, I really don't understand why they won't embed them in laptops.
Legal stuff maybe.
 
@kbok Some do.
@kbok Cost and power reduction
 
@sehe I've used bluetooth chips in robotics projects and I can guarantee you the power consomption is negligible on a laptop
When idle I mean.
 
auto death = [death](){ death(); }; this obviously would implode if it was allowed, but what stops it from being allowed?
 
I think it's more something along "the majority of users don't care so why should we"
@thecoshman It's not in scope when you define it
 
12:01 PM
@kbok is the error you're getting about ByteString not matching with Data.ByteString.Lazy.Internal.ByteString? I get that for some reason.
 
@R.MartinhoFernandes No
 
@thecoshman The fact that struct foo { foo f; } is not allowed.
 
@R.MartinhoFernandes I see...
@R.MartinhoFernandes but struct foo { foo* f; }; is allowed... so what forbids your no pointer version?
 
@thecoshman Because you can forward-declare it.
 
@thecoshman sizeof(foo)
 
12:05 PM
@R.MartinhoFernandes I don't follow
 
@thecoshman What is the size of struct foo { foo a; foo b; } ?
 
@kbok but struct foo; struct foo { foo f; }; wouldn't work either
@kbok I see :P
 
@thecoshman For a different reason.
error: variable 'auto foo' with 'auto' type used in its own initializer
 
@thecoshman Yeah, I mean, the pointer version is allowed because you can forward declare it.
 
that's for auto foo = [&foo](){};
However std::function<void()> foo{[&](){ foo(); }}; foo(); is allowed
3
 
12:07 PM
@R.MartinhoFernandes what's your code ?
There is ByteString and LazyByteString and I think they may conflict.
 
inb4 std::function<>
 
Also std::function<void()> foo{[&foo](){ foo(); }};
 
@ecatmur ah, and this will implode right?
 
@thecoshman yes
 
@kbok Argh, I can't create an ByteString to test.
 
12:08 PM
although it might tail optimise it
which turns it into an infinite loop, which can be optimised out
since infinite loops are UB
 
why can't it be auto foo{[&](){ foo();};?
 
@ecatmur Infinite loops are UB ? Since when ?
 
@kbok This compiles fine ideone.com/h2b9x.
I guess it should work if you can actually create a compatible ByteString.
@kbok Last year.
Not all infinite loops are UB, though.
Only those that make no sense.
 
ok.
 
Infinite loops that don't have externally observable behaviour are UB.
 
12:10 PM
Basically the standard makes non-termination not be observable behaviour.
Lunch time.
 
The utterly classic question:
 
@R.MartinhoFernandes Yup, liftM2 was what I was looking for. Thanks !
 
62
Q: Optimizing away a "while(1);" in C++0x

Johannes Schaub - litbUpdated, see below! I have heard and read that C++0x allows an compiler to print "Hello" for the following snippet #include <iostream> int main() { while(1) ; std::cout << "Hello" << std::endl; } It apparently has something to do with threads and optimization capab...

@thecoshman again, you can't use an auto in its initializer.
presumably because its type might depend on its type
 
hey everyone, I'm kind of new to C++, and I have some weird issues
I'm not certain I'm using static members correctly
so I have a Benchmark class, and a static member s_last
the first time I compiled and ran it, it worked perfectly
 
inb4 UB
 
12:20 PM
@ShdNx if you are using them, you probably shouldn't
 
then I made some changes to another file, rebuilt the solution, but noticed my changes weren't present
 
? noticed not present - how? what?
 
well, I added some extra cout-s to debug another issue
and the changes just didn't appear
so the old lines all ran
the new ones between them did not
 
I trust you have done a clean build ¬_¬
 
@ShdNx Can you tell? Did the old lines cout as well?
 
12:21 PM
well I assumed that Build -> Rebuild would do that for me
I'm using VS 2010 btw
 
@ShdNx post it on Stack Overflow with code?
 
yes, some of the old lines were cout-s as well
 
@ShdNx it does yeah
always do that :P
 
I will :P
 
well, okay, I can post it as an SO question
although it would be easier to just ask here
so if I have a static member
do I need to initialize it?
(explicitly?)
 
12:24 PM
depends on what type it is
 
on?
 
Jul 26 at 21:11, by jalf
If you want reliable, high quality answers quickly, use SO. If you want to gamble and maybe get a useful answer, maybe get a good answer, and maybe waste your time, feel free to ask questions here :)
 
IIRC static primitives are default (automagically) allocated, objects are not (depending on if they are a POD or not... which way around it is I forget)
 
@thecoshman default allocated?
 
@sehe: haha, I'll keep that in mind, thanks.
 
12:26 PM
there is a good question on what variables are automatically allocated under what conditions, but I don't have a link
 
Objects with static storage duration are zero-initialized prior to program startup.
 
@thecoshman initialized/constructed, I hope?!
 
They are then default-initialized.
(if no explicit initializer is provided)
 
@sehe don't call me out on these fancy technical terms :P
 
@ecatmur most likely, they actually reside in a physical data segment in the binary image. This is also what makes (made?) some programs with large static data compile slowly on gcc
@thecoshman Don't use them, then
 
12:28 PM
@sehe quite you
 
Saying 'allocated' there is really... a bit silly. That's ok, but it is also confusing, and that's slightly less ok
 
@sehe yeah, .bss, .data or .rodata.
.bss if they are zero-initialized and not constant-initialized, and their zero-initialization is also bitwise zero, obviously
 
@sehe I wouldn't think so... I guess initialised is a bit better, allocated is more about the memory being set aside for a value to be plopped into
 
or if their constant-initialization is bitwise zero (for completeness).
 
9
Q: Long compilation time for program with static allocation

PredragI would really appreciate if somebody could tell me why compilation of this program: double data[123456789]; int main() {} takes 10 times longer then compilation of this one: int main() { double* data=new double[123456789]; } when both are compiled with: $ g++ -O0 and the executabl...

 
12:33 PM
Hm, would const static solely-zero-initialized objects go in bss or rodata?
 
Implementation defined
It's allowed to go in rodata (because mutating const data (with casts) is UB)
 
hm, looks like gcc puts it in rodata
which is a bit of a waste of space, but then it's a pretty stupid thing to have anyway.
I once had a colleague who went around writing things like static T zero_t = {0, 0, ...}; t = zero_t; in the belief that it would be "faster" than t = T().
 
The example on this page, does the make_unique not require std::?
oh wait, derp moment :P
 
@thecoshman There is no std::make_unique yet, what you see there is a custom definition.
 
make_unique is the phantom of the std.
 
12:46 PM
@FredOverflow yeah, I saw that :P
 
@FredOverflow Adding make_unique yourself is quite easy, yet it's damn annoying that you have to do it for every code base, again and again..
 
so, you would still have to do auto sharedInt = std::unique_ptr<int>(new int(5));?
 
How could they forget to add something so important ..
 
@thecoshman No, you write and use make_unique. Sheesh.
 
@thecoshman std::unique_ptr<int> sharedInt(new int(5));
 
12:48 PM
I would have thought boost would have picked up the slack with this one :P
 
Just be sure to always create named unique_ptr objects before passing them.
#define make_unique __COUNTER__
Doing it wrong :P
 
very
#define make_unique Guid::Create()
 
Meh, not a compile-time constant.
#define make_unique new unique()
 
Who says Guid::Create() isn't constexpr? I mean, TMP is Turing-complete :)
 
@sehe Nice save.
 
12:54 PM
@StackedCrooked That is by definition not constexpr
 
Well, I only typed that because I thought you had lowered the level to non compile-time constants.
 
Another newbie question: I implemented a template<class T> class ptr type. I know that such thing as template specialization exists in C++. How can I extend the class with more members if T = int? Do I have to copy the whole existing code?
Or can I just do stuff like
template<class T = int>
int ptr::incr()
{
...
}
 
no
more like...
 
int ptr<int>::incr() maybe?
 
templatae<typename T> Foo{
}
template<int> Foo{
int magik;
}
of course you need to use class/struct in there
 
12:59 PM
but then will the latter type have the same members as the former one?
e.g.
 
@ShdNx You can create a specialization that inherits from the default type and add new members to its body.
Or a common base class.
 
Why does <- remove the monad ?
 
nope, create a foo with any type other than int will have no members, creating it as an int will give it the one int called magik
 
okay, but how can I tell the compiler that it's the default type I want to inerit from?
template<int>
class ptr : ptr<int> ?
wouldn't ptr<int> refer to the class being declared?
 
@StackedCrooked oh yes?
 
1:01 PM
Ok, that doesn't seem to make sense.
 
@StackedCrooked surely you will end in an endless loop?
 
Compile-time loop :P
 
AFAIK if you do specialisation, you would have copy the generic types over, and manual specialise them
 
yeah I tried it, the compiler said "no thanks"
 
template<typename T> class ptr : base<T> {}; // put common stuff in base
template<> class ptr<int> : base<int> {};
 
1:03 PM
I think I'll go with the common base type approach
thanks!
 
@ShdNx put the common stuff in a base class template
 
yeah, that's what I concluded as well - thank you!
 
⁐ ⁓
 
@StackedCrooked square of unicode death
 
Attempt at a fancy wink. Looks a bit creepy instead.
 
1:04 PM
@StackedCrooked -_o
 
I think ⟺ I am
 
:D
 
This is a list of Unicode characters. C0 Controls and Basic Latin {| class="wikitable sortable" !Code !Result !Description !Abbreviation |- | U+0000 | | Null character | NUL |- | U+0001 | | Start of Heading | SOH |- | U+0002 | | Start of Text | STX |- | U+0003 | | End-of-text character | ETX |- | U+0004 | | End-of-transmission character | EOT |- | U+0005 | | Enquiry character | ENQ |- | U+0006 | | Acknowledge character | ACK |- | U+0007 | | Bell character | BEL |- | U+0008 | | Backspace | BS |- | U+0009 | | Horizontal tab | HT |- | U+000A | | Line feed | LF |- | U+000B | | ...
^ Lot's of them here.
 
Is there constructor delegation in C++?
Like in C#:
class Foo : Base
{
public Foo(int stuff) : base(stuf)
{
...
}
}
 
It is a C++11 feature that is not yet supported by all compilers.
I believe GCC 4.8 has it. Maybe 4.7
 
1:08 PM
And I don't suppose constructors are inherited as well, are they?
No, that would be silly.
 
But you can always do constructor delegation in C++03 by introducing a base class.
 
well, now I just renamed the current ptr<T> class to base_ptr<T>
and I'm making the "normal" ptr<T> class
 
@ShdNx If Button inherits from Widget then the order of constructors called is: Widget, Button. The order of destruction will be: Button, Widget. So all constructors are called. I don't know if that's what you meant with inherited?
 
okay, but if base_ptr<T> has a construtor with the parameter T, but ptr<T> doesn't
but ptr<T> inherits from base_ptr<T>
 
@StackedCrooked is that not only for default constructors?
 
1:10 PM
Then ptr<T> must call the base_ptr<T> constructor with that parameter.
 
I can't initialize a ptr<T> instance using the constructor in base_ptr<T>
right?
 
I do so little inheritance :P
 
how can I call base constructors? :O
 
@thecoshman No, why should it be different for non-default constructors?
 
that's what I asked - if there was constructor delegation
 
1:11 PM
@ShdNx C++ 101 much? :)
 
@StackedCrooked :P I have no idea
 
yeah I have no idea what I'm doing :D
but that's why you're here, to help me ;)
 
struct A : B { A() : B(1) {} }; // here the constructor of A calls the constructor of B
 
@ShdNx that's valid C++ (modulo typos)
 
@ShdNx Yes, that is my purpose in this place. How can I please you master?
 
1:12 PM
@ShdNx I wouldn't stick to that theory, it will not last long around here
 
It may work on me as long as I'm sleep deprived.
 
okay, okay :D
 
This STL guy knows his shit, but my good is 'stood pooter' funny as fuck
 
It's common among Microsoft programmers.
Herb says it too.
 
I just don't get it, it's an abbreviation of pointer, so say pointer
 
1:22 PM
I also think it's silly.
stood shared putter, stood vector, unique putter. It's like some hillbilly family.
3
 
hello ,friends.. im From india .
 
Okay, I tried your idea with the base class thing, but I get the following compiler error:
error C3855: 'ptr': template parameter 'T' is incompatible with the declaration
template<int>
struct ptr : public base_ptr<int>
on this line
 
what's base_ptr?
 
any idea what this could be?
template<class T>
class base_ptr
 
In a .NET site, what would you use to force a user to not be able to advance into the next screen given a certain condition even if they click the continue?
 
1:28 PM
hmmm... not sure, I've not done huge amounts of template stuff with inheritance
Aug 12 at 10:41, by Cat Plus Plus
If you are new here, read the code of conduct now. Thank you.
 
sorry, wrong room again
 
morning :)
 
afternoon :)
 
#define morning I_JUST_GOT_UP
 
Is only 9:40, definitely still morning.
 
1:39 PM
you fellows need to get into the right place in the world
 
But I live in 'Mericuh!
 
Good morning! I just wrote the following line:
(*this)((**this) + 1);
I think I'll just go and shoot myself.
 
@SamDeHaan wrong place
 
(Problem is, it works.)
 
@thecoshman Probably true - but, as I live in 'Mericuh, I am obligated to think that there is nowhere better. It's required for citizenship.
 
1:44 PM
@ShdNx neat :p
what the hell are you doing though...
 
@SamDeHaan as is being wrong
 
@melak47: you don't want to know, trust me.
Btw, the solution to my earlier problem is:
template<>
struct ptr<int> : public base_ptr<int>
 
@thecoshman And we're really good at it, too!
 
@SamDeHaan shut up and eat another cake whilst killing some foreigners :P
 
@thecoshman Hmm, you look like a foreigner... Cake or death?!
 
sbi
1:55 PM
room topic changed to Lounge<C++>: const std::string morning = "I just got up"; [c++] [c++11] [c++-faq] [fun] [nsfl]
 
@SamDeHaan death by cake
obviously
 
Hmm, we're flat out of cake. Pick again.
 
@sbi #define morning I just got up
 
sbi
@thecoshman #define? Over my dead body.
 

« first day (669 days earlier)      last day (4279 days later) »