« first day (460 days earlier)      last day (4490 days later) » 

9:00 AM
that reminds me, I think my library actually assumes 16-byte is max alignment
 
@FredOverflow Btw, aligned_storage takes a second parameter (defaulted) that is the alignment.
 
@jalf Oh, I just remembered you recently commented on __thread for GCC.
I've been using __thread std::array<void*, N> for a while, is that just wrong?
 
anyway to loop through array like for (i in array) {}
?
 
@anonymouslyanonymous for(auto&& element: container) { ...
C++11 only.
 
@LucDanton hmm, what did I say?
 
9:03 AM
thanks
 
@jalf It's not close to C++11 TLS as it supports only some types, IIRC.
 
Well, last I checked it didn't compile if you used it on non-POD types
so I'm a bit surprised to see that.
 
So am I.
 
anyway, check if it calls the destructor when the thread exits
if it does that, then I'm happy :)
 
But then std::array<void*, N> is a POD, isn't it?
 
9:05 AM
is it?
 
It is.
There's nothing non-PODy in it.
 
Mystery solved. (-ish, I'm not checking the Standards.)
 
Pointers are PODs, and so are arrays of them, and so is a struct with one array of them in it.
 
@RMartinhoFernandes private part?
 
but it has a private member
and a constructor
 
9:06 AM
@Abyx No longer relevant.
@jalf No constructor.
It's aggregate initialization all the way down.
 
ah
 
@RMartinhoFernandes Actually there's still the requirement that all members have the same access rights. This was already true for C++03. Isn't there?
 
@LucDanton There's only one data member.
But yes, that requirement is there.
 
class pod { int i; }; has a private member and is a POD according to C++03 rules.
 
hmm, that'd explain it then. But just for fun, could you try __thread std::string or something? Something that's definitely non-POD?
 
9:07 AM
@RMartinhoFernandes data, size, begin... ?
 
Pedant.
Fixed.
 
Let me check C++03 for a moment.
 
Oh, C++03 requires public.
This "all the same access" is a relaxation.
It's all in the FAQ question.
 
so it's not POD then?
 
> A relaxed rule here is that standard-layout classes must have all non-static data members with the same access control. Previously these had to be all public, but now you can make them private or protected, as long as they are all private or all protected.
 
9:10 AM
oh wait
 
@jalf It would not be in C++03, but std::array is not C++03.
 
POD then
 
17
A: What are Aggregates and PODs and how/why are they special?

R. Martinho FernandesWhat changes for C++11? Aggregates The standard definition of an aggregate has changed slightly, but it's still pretty much the same: An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equal-initializers for non-static data members (9.2),...

 
damnit, can't someone just run std::is_pod<...> and double-check? ;)
 
DAmn.
Wrong window.
 
9:12 AM
Something about pointer-to-member operators.
I don't even remember what I was doing before that.
 
@jalf Happy: ideone.com/j7Jsx
Oops.
Damn.
I'm not starting the day very well.
 
I don't even remember what I was doing before that.
 
You said that.
Twice.
 
(Getting a lot of retries, but the end result looks okay on my end so I say it's fine.)
 
@RMartinhoFernandes What part of for_dummies did you not understand? ;)
 
9:17 AM
ok, so __thread probably still doesn't support non-POD, but std::array<void*,N> is POD in C++11
 
@jalf Are you sure the array member is actually private?
 
@FredOverflow It's not part of the public interface.
 
That doesn't mean it's private :) It could just mean that the standard doesn't specify how it's named.
 
> The member variable elems is shown for exposition only, to emphasize that array is a class aggregate. The name elems is not part of array’s interface.
 
9:18 AM
@FredOverflow does it make a difference?
 
Of course, it can either be public, or compiler magic.
 
the class is POD either way
 
T __reserved_by_the_implementation_bitch[N];
 
@RMartinhoFernandes In GCC, the array member is public, and it is called _M_instance.
 
Yes, but it could be private with magic :)
 
9:20 AM
Now I have doubts about what behaviour a pointer_to_member functor should have.
 
"not part of the interface" means you cannot rely on it being called elems.
@RMartinhoFernandes I don't believe in magic :)
 
FTR, that's exactly how it rolls in Hell++. takes note.
@FredOverflow You don't have to believe in it for it to exist. This is not the Discworld.
I think.
 
never read Discworld
 
Reading that answer by @MooingDuck...
> However, placement new is designed for internal buffers, which were themselves not allocated with new, which is why you shouldn't call delete on them.
This is bollocks too, isn't it?
Proof by std::vector.
 
Well, proof by some implementations of std::allocator.
 
9:26 AM
That's not as catchy.
 
@RMartinhoFernandes Well, something in that answer doesn't add up. Of course you should never call delete on something you constructed with placement new inside an existing buffer
regardless of how that buffer was allocated
 
@RMartinhoFernandes std::vector does not allocate with new, it allocates with an allocator, and the default allocator allocates with operator new.
 
That's not as catchy.
I placed a -1 on it. Did you hear that @MooingDuck? That answer needs to be made clearer.
Well, I had at shot at fixing some things that were definitely just wrong, and people can't be wrong on the Internet.
-1 removed, but I'm still not happy with the "designed for internal buffers" paragraph.
 
@RMartinhoFernandes It has to be new (&a.buffer) MyClass() (note the ampersand).
a.buffer is not (necessarily) an array. It doesn't compile without the ampersand on GCC.
 
Oh, you're right. Fixed.
@FredOverflow Yeah, it's an union.
At least I didn't use std::aligned_storage<sizeof(MyClass)> directly (note the missing ::type).
 
9:35 AM
Who'd do that.
 
And do we really need struct thingy anymore? Why not simply std::aligned_storage<sizeof(MyClass)>::type a; inside main?
Also, you should #include <type_traits>.
 
@FredOverflow No idea. The thingy thingy was never needed in the first place.
 
And the return 0; is superfluous.
 
Stop it, it's not my answer.
I'm not going to make it perfect, just good enough.
 
Software at its finest.
 
9:37 AM
Sorry. Once I get started, it's hard to stop.
 
I also fixed the calls to new char[] and delete[] in the first snippet.
 
@RMartinhoFernandes It would probably be a good idea to hide the constructor of aligned_storage so that mistake can never be made.
Or the constructors of all meta-functions, while we're at it. Or would that pose any problems?
 
@FredOverflow Can't.
Traits need to be default constructible, for some reason.
 
What's the precise reason?
 
9:40 AM
Put them into std::tuples!
 
But the standard requires it.
 
dang
 
Then template<typename... Traits> void foo(std::tuple<Traits...>); can deduce multiple traits at the same time!
 
I use my template aliases, so I don't get bitten. meta::aligned_storage<sizeof(T)>.
 
@RMartinhoFernandes By the way, did you ever fall into this trap? I did once :)
 
9:42 AM
@LucDanton Just as void foo(Traits...), no?
 
@RMartinhoFernandes Yes. I liek tuples.
 
Still requires the default-constructible, though.
@FredOverflow Yeah, once. But the paranoia grows on me quickly.
 
9:54 AM
namespace adl { using std::get; } template<int Index, typename Tuple> using tuple_element = decltype(adl::get<Index>(std::declval<Tuple>()));
that sensible?
I'm just gonna try it.
 
I think it's missing something.
 
For the ADL trick, right? I don't think I got it right.
 
I think you need a get function in the namespace, that uses "naked" get in decltype.
 
Whoops, I seem to have a specialization of tuple_element somewhere in my library.
 
9
A: How do I write an ADL-enabled noexcept specification?

Johannes Schaub - litbI think I would move it into a separate namespace namespace tricks { using std::swap; template <typename T, typename U> void swap(T &t, U &u) noexcept(noexcept(swap(t, u))); } template <typename T> void swap(my_template<T>& x, my_template<T>&...

 
10:01 AM
ahh, that sweet feeling knowing that there is nothing that you need to do but wait on others
 
How does the noexcept-spec of tricks::swap not end being recursive anyway? Is the name swap not yet declared at this point?
 
Hmm. Good point.
But since it works, I guess it isn't.
 
2
Q: Can copy elision happen across synchronize-with statements?

edA-qa mort-ora-yIn the example below, if we ignore the mutex for a second, copy elision may eliminate the two calls to the copy constructor. user_type foo() { unique_lock lock( global_mutex ); return user_type(...); } user_type result = foo(); Now the rules for copy elision don't mention threading, but I...

assuming the user_type constructor does something that uses a shared resource is that bad?
 
@RMartinhoFernandes That is just some practice problem?
 
@MrAnubis No, that was really a problem I ran into.
 
10:11 AM
@RMartinhoFernandes what does this do : std::declval<T>?
 
template <class T>
typename add_rvalue_reference<T>::type declval() noexcept;
It's a function without definition.
 
@RMartinhoFernandes aah converts any type T to a reference type
 
It's for use in unevaluated contexts when you need a T, but don't want to require it to be default constructible.
If I wrote noexcept(noexcept(swap(T(), T()))), this would only work for types with a default constructor.
But with that declval trick, I don't need to require any constructor.
 
@RMartinhoFernandes aah, got it , Thanks
 
10:26 AM
I wouldn't be in this tuple_element mess if I had ref-qualifiers.
 
10:38 AM
Is the usage with_signature<int(double)>::Constructible<Foo> confusing? (This is a concepts library.)
 
@tony hey, did you know Reddit is back up
 
@thecoshman why shouldn't it be? The SOPA thing was yesterday
 
@jalf ¬_¬ you're not familiar with Reddit are you
 
Did you know /r/banana is at war with /r/pickle?
5
 
10:50 AM
No, no I did not know that
 
@thecoshman yes I know, my life has meaning again :P
 
I'm pro-bananas.
I hope none of you is a pickle lover.
 
yep, there is a war
here's the war declaration... :P
 
@RMartinhoFernandes I like both :(
though neither are good on there own
 
sbi
std::motivation_failure up("Why should I care?");
throw up;
 
11:03 AM
banana, meh; banana split, yum yum!
pickle, meh; pickle in/on your burger, yum yum!
 
-2
Q: Path to be a guru in a low-leve language (C and/or C++)

UmNyobeI recently tried to explain to somebody how to become a C guru without being one myself. You know, the kind of guy which can respond to a simple answer like why a single loop so much slower than 2 loops by a wonderful response based on analysis. In my opinion, this should be : learn about alg...

First step in the path to be a guru in C and/or C++: learn instead of asking these silly questions.
 
there is of course the indisputable fact that pickoffe is not a flavour... yet ¬_¬
 
Pickles suck.
 
@stephenfry The awkward moment when you break the law you proposed #StopSOPA http://twitpic.com/88ueqz via @twit-pic
lol!
 
11:08 AM
Hurray, now I have template aliases sprinkled in my codebase. And that's what matters.
 
sbi
Is not metaprogramming if you are still understand it after 2 week.
2
 
Xeo
Sigh, another helpdesk question...
 
Hmmm SexyAppFramework.
I'm closing as general reference.
 
Xeo
Sorry, I wrote the comment from my dumb phone and couldn't be arsed to grab the link. :P
 
11:22 AM
14
Q: What do people mean when they say C++ has "undecidable grammar"?

jjujumaWhat do people mean when they say this? What are the implications for programmers and compilers?

^ I thought the chosen answer was incorrect, until I then thought of a counterexample.
 
@Xeo ergh, I just HAD to fix that grammar
and formatting, and Engrish
 
It seems that C++ is undecidable because the implementation-defined template recursion limit has a loophole: operator-> drill-down is allowed to endlessly call different templates, but they aren't nested so the compiler isn't allowed to terminate.
Is this the only reason C++ grammar is undecidable?
 
I'd guess so.
16 hours ago, by R. Martinho Fernandes
operator-> is a strange beast.
 
Xeo
I wonder what fun stuff could actually be done with operator->...
 
@RMartinhoFernandes huh, I always though that -> was just implied short hand for (_OBJECT_*).
 
Xeo
11:29 AM
@thecoshman Overloaded operator->
 
@Xeo yeah, didn't know you could overload it
 
Xeo
It either has to return a pointer, or another thing that overloads operator->. Ultimately, a pointer must be returned.
 
It's weird, because it returns a pointer.
 
Or something else!
 
Xeo
@CatPlusPlus Yeah, but otherwise things would get hairy
 
11:29 AM
Not what you'd expect from a operator that's supposed to be shorthand for dereferencing.
 
Xeo
I mean, look at operator->*
 
@Xeo Things are already hairy.
 
It's possible there are other loopholes, such as recursion that occurs before or after instantiation. Are SFINAE conditions considered to be nested instantiations?
 
operator->* just has weird priority.
Besides, when was the last time you've used ->* or .*.
std::function/std::bind all the things!
 
Last month.
 
11:31 AM
@Xeo I keep telling people this… operator->* is just a binary operator like operator+ or operator/.
 
Xeo
@CatPlusPlus It's not only the priority
5
A: How to overload the ->* operator?

XeoThe return of operator->* represents a function in the process of being called, with the only missing parts being the parameters. Thus, you must return a functor that invokes the given function on the given object with the given parameters: // PTMF = pointer to member function template<cla...

 
@Xeo It is only the priority. It has highest priority among the overloadable binary operators.
 
It has lower priority than () which is an endless source of fun and confusion.
 
@CatPlusPlus That's the postfix function call operator (), not the grouping parens.
 
Xeo
Well, that aside, how else should an overloaded operator-> be implemented if not by returning a pointer?
 
11:35 AM
@Potatoswatter That still makes it an endless source of fun and confusion.
 
-1
Q: how returning reference work here

10001001058Why this code works (matrix is a class): const int max_matrix_temp = 7; matrix&get_matrix_temp() { static int nbuf = 0; static matrix buf[max_matrix_temp]; if(nbuf == max_matrix_temp) nbuf = 0; return buf[nbuf++]; } matrix& operator+(const matrix&a...

 
Xeo
2
A: Returning a reference can work?

LaceySnrbuf is declared as static, meaning it retains it's value between calls to the function: static matrix buf[max_matrix_temp]; i.e. it's not created on the stack as int i = 0; would be (a local variable), so returning a reference to it is perfectly safe. This code is dangerous, because the memor...

 
Dupe.
 
@RMartinhoFernandes Yeah, just wanted to clarify. Obviously nothing has higher precedence than the grouping parens.
 
Xeo
I'm a bit lost in the comments
Seriously, that 1000100...whatever guy seems hopeless. I wonder how old he is...
 
11:37 AM
12
Q: Are free operator->* overloads evil?

PotatoswatterI was perusing section 13.5 after refuting the notion that built-in operators do not participate in overload resolution, and noticed that there is no section on operator->*. It is just a generic binary operator. Its brethren, operator->, operator*, and operator[], are all required to be no...

 
@Xeo Profile says 19.
The funniest part is "please enlighten properly".
 
1
A: Overloading member access operators ->, .* (C++)

Potatoswatter-> This is the only really tricky one. It must be a nonstatic member function, and it takes no arguments. The return value is used to perform the member lookup. If the return value is another object of class type, not a pointer, then the subsequent member lookup is also handled by an operato...

 
room topic changed to Lounge<C++>: No questions about asking questions. Violators will be shot. Survivors will be enlightened properly. [c++] [c++11] [c++-faq]
 
> Ex: 01 = A, 02 = B, 03 = C, so on...., 90 = Z
WTF?
 
Xeo
I remember operator->* being brought to good use by the Catch unit testing framework
 
11:41 AM
Great, someone flagged @Feeds!
 
Ban the bot!
 
@RMartinhoFernandes think your going to need to expand that :P
 
-4
Q: Get ASCII character from number in C/C++

Sudheer Rajumy requirement is, when I input a number (say 01 - 100), I should be able to get the ASCII code value for that number. Ex: 01 = A, 02 = B, 03 = C, so on...., 90 = Z, and if number is 91 = AA, 92 = AB, 93 = AC, etc... All I could get from googling, etc...was to convert int to a char, get ASCII v...

 
Probably flagged automatically by a PHP script anyway.
 
11:43 AM
He's right about one thing: it's hard to google how to use that retarded encoding.
 
@RMartinhoFernandes I am actually laughing out loud.
 
@RMartinhoFernandes yet another reason why pot is bad :P
 
@Potatoswatter You evil fiend.
 
How did he decide on 90? Why not 80 or 95?
 
He must've worked on EBCDIC.
 
11:56 AM
weird , some guy from the Philippines tried to access my facebook account. &_&
maybe it wasn't exactly wise to submit my complete name and address at every damn site I visited for the past 3 years. "_"
 
@IntermediateHacker As in, impersonating you?
 

« first day (460 days earlier)      last day (4490 days later) »