« first day (467 days earlier)      last day (4481 days later) » 

user142019
12:01 AM
I have a little problem with variadic templates…
 
> /dev/loop0: No such device or address
WTF?
 
Xeo
lol
 
user142019
template<class ...T, class ...U>
struct Reaction {
  Product<T...> product1;
  Product<U...> product2;
};
 
user142019
I know this is impossible and I understand why,
 
Xeo
pack them
 
user142019
12:02 AM
How would I do that?
 
template <typename...> struct pack {};
 
user142019
ah
 
Before you mention it, yes, it's annoying.
 
user142019
:p
 
Xeo
template<class...> struct pack{};

template<class P1, class P2>
struct Reaction;

template<class... T, class... U>
struct Reaction<pack<T...>, pack<U...>>{
  // ...
};
 
user142019
12:04 AM
template<class...> struct ReactionPack_ {};
template<class P1, class P2> struct Reaction;
template<class ...T, class ...U>
struct Reaction<ReactionPack_<T...>, ReactionPack_<U...>> {
  Product<T...> product1;
  Product<U...> product2;
};
 
user142019
Works, thanks!
 
Xeo
If only we could say blargh<int, float, bool | foo, bar, zing>
to seperate two variadics :|
 
user142019
You can do it using a separate class
 
user142019
which acts as an "ignore" type.
 
user142019
Like Reaction<int, float, Separator, float, float, double>
 
Xeo
12:07 AM
Well, sure you can do, but it's still annoying as hell to split that then
 
user142019
:P
 
@WTP Now you need to iterate through that and collect each half. :S
 
user142019
 
user142019
Still need to fix some errors.
 
user142019
LOL GCC is mad at me.
 
Xeo
12:11 AM
@WTP Element needs a constexpr constructor and shouldn't have a std::string member, just have a char const*.
 
user142019
@Xeo If I change that to char const* then operator() won't compile.
 
user142019
I would have to do symbol.c_str() then.
 
You can't have a constexpr constructor if you have a std::string member.
 
Xeo
Huh? No. The member of the other Element will be a char const* too
 
user142019
operator() calls the constructor.
 
user142019
12:14 AM
Aaah you were talking about the member :p I see now
 
user142019
For some reason the compiler doesn't like the operator>.
 
Xeo
braced initialization really makes constexpr functions kinda nice...
 
user142019
main.cpp:79:24:{79:3-79:23}{79:26-79:49}: error: invalid operands to binary expression ('const Product<Molecule<2U>, Molecule<1U> >' and 'const Product<Molecule<2U>, Molecule<2U> >') [3]

main.cpp:71:32: note: candidate template ignored: substitution failure [with T = <Molecule<2>, Molecule<1>>, U = <Molecule<2>, Molecule<2>>] [3]
 
Xeo
hm, the second operator- is gonna be hard
 
user142019
Everything compiles fine except for operator>.
 
Xeo
12:17 AM
Paste it
 
user142019
Here is the new version ideone.com/hVaiV
 
user142019
Compile errors are five chat messages above.
 
Xeo
Your constexpr functions are wrong, you can only have a single return statement in them
 
constexpr R f(A...) { return something; } You can't have anything else in a constexpr function.
Except for static_asserts, that is.
 
user142019
So I have to do operator- using overloading and recursion, right?
 
12:20 AM
Why do you need things to be constexpr?
 
user142019
you are right :p
 
user142019
That's not needed.
 
Xeo
constexpr Molecule<2> operator-(const Element& element1, const Element& element2) {
  return Molecule<2>{{element1, element2}};
}
Is one option. :)
template<class ...T, class ...U>
constexpr Reaction<T..., U...>
You're missing the ReactionPack_s here
 
@Xeo List initialization is sweet.
 
Xeo
Aye, it indeed is
 
12:24 AM
Also, no need to repeat the type name, the constructor is not explicit.
 
user142019
Like this?
 
user142019
template<class ...T, class ...U>
Reaction<ReactionPack<T...>, ReactionPack<U...>> operator>(Product<T...> prod1, Product<U...> prod2) {
  Reaction<ReactionPack<T...>, ReactionPack<U...>> return_reaction;
 
3
Q: What is the reason for "locks are an expensive operation" to be uttered so often?

Tony The LionI have read a lot of material on threading, and all the synchronization mechanisms involved. I also understand the dangers of not doing it properly. I just watched this PDC 2009 video about Parallelism and Concurrency, and here is yet again this mention that "locks are an expensive operation"...

 
Xeo
Nearly
 
time to repwhore :)
 
Xeo
12:25 AM
@WTP You can't create automatic variables in a constexpr function...
Okay, I got it down to one error
 
user142019
I got it down to… three errors.
 
Xeo
On the second operator-, because that one's a bitch
 
user142019
/Developer/usr/bin/../lib/c++/v1/tuple:446:23: error: attempt to use a deleted function [3]
 
Xeo
lol
Whatever you're doing, you're doing it wrong xD
 
I got it to compile, but what is it supposed to do?
 
user142019
12:26 AM
ideone.com/3IUO4 <— updated, all constexprs removed
 
user142019
LOL it compiles fine on Ideone. -_-
 
user142019
fuck libc++.
 
user142019
There is no output function called.
 
Xeo
Well, @WTP, I got it down to one error with constexpr functions :)
 
user142019
nice
 
Xeo
12:28 AM
template<unsigned N>
constexpr Molecule<N + 1> operator-(const Molecule<N>& molecule, const Element& element) {
  Molecule<N + 1> return_molecule;
  for (size_t i = 0; i < N; ++i) {
    return_molecule[i] = molecule.elements[i];
  }
  return_molecule[N] = element;
  return return_molecule;
}
@RMartinho, any idea how to elegantly constexprify this?
 
user142019
return_molecule[i] must be return_molecule.elements[i] since Molecule doesn't have operator[].
 
Xeo
that aside
Oh shit, list initialization is even sweeter than I thought...
template<class ...T, class ...U>
constexpr Reaction<ReactionPack_<T...>, ReactionPack_<U...>> operator>(Product<T...> prod1, Product<U...> prod2) {
  return {prod1, prod2};
}
No mentioning of Reaction<...> inside the operator :)
 
@Xeo Working on it. I call it the "indices" trick. You probably know what I mean.
 
user142019
@Xeo fuck yeah that makes it compile.
 
6 mins ago, by R. Martinho Fernandes
Also, no need to repeat the type name, the constructor is not explicit.
What did I tell ya?
 
user142019
12:31 AM
Now going to write an overload for operator<< for ostream
 
Xeo
Oh, I overlooked that
Tony's message moved it out of the screen
 
user142019
Progress… ideone.com/SanrM
 
Xeo
Guys, I really love bleeding edge compilation...
 
Any idea what g++ means here?
a.cpp: In function 'constexpr Molecule<2u> operator-(const Element&, const Element&)':
a.cpp:38:23: error: invalid return type 'Molecule<2u>' of constexpr function 'constexpr Molecule<2u> operator-(const Element&, const Element&)'
 
Xeo
lol, body?
 
12:35 AM
constexpr Molecule<2> operator-(const Element& element1, const Element& element2) {
  return {{ element1, element2 }};
}
clang is fine, but clang doesn't have constexpr for real.
 
Xeo
It does
Guess what I'm compiling with all this time
 
Xeo
3 mins ago, by Xeo
Guys, I really love bleeding edge compilation...
 
Right, but 3.0 doesn't have it, does it?
 
Xeo
Nope
 
12:36 AM
And that's the one I have.
So, I can't trust it.
 
Xeo
And I had to hack libc++'s <__config> header to make it work for me...
 
Wait, GCC 4.7 is fine.
 
Xeo
lol?
 
Yay, everything constexpr!
 
Xeo
Mmm, is there any way to make an operator= constexpr?
 
12:37 AM
Posting in a minute. What is this supposed to do?
@Xeo No, that's silly.
 
Xeo
Thought so
 
I mean, you probably can, but not meaningfully.
 
Xeo
@WTP, why the operator! ... ?
 
user142019
@Xeo to convert an element to a molecule. Elegant way comes later, as always.
 
user142019
12:39 AM
aka never
 
Xeo
@WTP When you have operator+(molecule, element)?
 
user142019
@Xeo never.
 
Xeo
No, I meant, you have that thing already.
No wait, you got operator-
 
Guys, how do I test that this is correct? I've been fixing code I have no idea what it is supposed to do, meaning I can't be certain it's correct. It's driving me mad.
 
Xeo
Use the output function from some dozen pastes ago
No wait, that's the fixed version...
@RMartinhoFernandes To output a reaction, output the products, each molecule seperated by +, and each product seperated by ->
 
12:43 AM
I think I've found it.
But I don't think it's usable without a lot of hammering.
 
Xeo
aye
Your op_minus_impl is btw not constexpr
 
Xeo
Because it's missing the keyword?
 
Oh, I fixed that :)
Reload the page.
Ah, screw it, I'm going to have the compiler print the typenames in an error message first...
 
why can't excel do =MOD(2650800129,10)?
 
Xeo
12:48 AM
Hm, Clang doesn't like your indices trick it seems..
 
It's valid!
 
Xeo
> t.cpp:51:20: error: ambiguous partial specializations of 'build_indices<0, indices<1, 2> >'
 
Err, how is it ambiguous?
Hmm, I think I get it.
I can fix that.
 
Xeo
It indeed is
 
template <unsigned... List> struct build_indices<0, indices<List...>> { typedef indices<List...> type; };
There, no longer ambiguous.
 
Xeo
12:50 AM
Right
 
hello
 
All types are correct.
 
Xeo
Uuuh, you added an operator[] to your Molecules :(
 
is anyone an expert on XPath and PMD?
 
Xeo
Uhm, robot?
 
12:52 AM
What?
 
Xeo
Your indices are 1-based, right?
 
Oh, damn, I knew I was going to get something wrong.
I thought it would be the order though.
 
Xeo
Yeah, I get an out-of-bounds warning with clang
 
3.0 doesn't warn me :(
 
support.microsoft.com/kb/119083 "The MOD() function returns the #NUM! error if the following condition is true: ('divisor' * 134217728) is less than or equal to 'number'"
friggin microsoft
 
12:54 AM
lol
 
Xeo
So, it's a simple -1 that was missing
  typedef typename build_indices<N-1,
      indices<N-1, Tail...>>::type type;
               ^~
Compiles fine and without errors now
 
Xeo
@RMartinhoFernandes -Wall -Wextra?
 
Always.
I have it aliased.
 
Xeo
k
same
 
12:55 AM
0
Q: Synchronous reading from IOBuffer

user1170366How can I implement the following behavior? void thread1_func(ostream& os) { sleep(10); os << 12; sleep(10); os << "text"; sleep(10); os << MyObject(); } void thread2_func(istream& is) { int i = 0; std::string str; MyObject obj; ...

I have my doubts
 
Xeo
> alias clang++='clang++ -std=c++0x -stdlib=libc++ -Wall -pedantic'
Okay, I do not have -Wextra aliased
 
-Wextra?
 
@TonyTheLion I see a sleep call there. Without looking further, I'm guessing it's a mistake.
@MooingDuck Yes, like extra cheese.
 
is >> 12 is that even correct?
 
posted on January 26, 2012 by Scott Meyers

In what has in recent years become an annual pilgrimage to Stuttgart, I, in collaboration with QA Systems, will conduct three open-enrollment seminars in September.  Each is two days long.  As with all my public presentations, you'll find details at my Upcoming Talks page. To save you the trouble of clicking through that, here's the summary: 17-18 September 2012 Effective C++ in an E

 
12:57 AM
No.
 
I thought so
but I doubt that overloading the streaming operators to implement waiting on threads is a good idea
 
user142019
Mmm I need to print all elements in a tuple.
 
Xeo
@Feeds Holy shit, that sounds awesome!
Now I just need to get to Stuttgart
 
@WTP It's somewhere on SO.
 
Xeo
11
A: Pretty-print std::tuple

XeoYou need compile-time recursion for that: #include <tuple> #include <iostream> template<class Tuple, std::size_t N> struct TuplePrinter{ static void print(std::ostream& o, const Tuple& t){ TuplePrinter<Tuple,N-1>::print(o,t); o << ", " << st...

5
A: Deducing std::function with more than two args

Xeo This won't compile function_type_deducer([](){}).describe_me(); It would work if function_type_deducer wasn't a template. :) Non-capturing lambdas (empty []) are implicitly convertible to function pointers. Sadly, implicit conversions aren't taken into consideration for some template argumen...

@WTP Pick one, I do it in both (and in different ways).
Dammit, why does Stuttgart have to be at the other end of Germany -.-
 
1:01 AM
Ah, damn, I need to setup coloured output for GCC 4.7.
Or simply make it my system's default GCC...
 
Xeo
Or use Clang 3.1 tot
 
Need to build that.
Today's attempt failed at some point, but I didn't have time to investigate.
 
user142019
Oooohhh yeaaah ideone.com/gbRNs :D
 
Xeo
lol, ideone complains
 
user142019
because of the range-based for
 
1:04 AM
No range-based for.
 
Xeo
ah, range-based for
 
user142019
But with clang it works great.
 
Xeo
Curse you, slow network!
 
hello
 
user142019
1:04 AM
hi
 
user142019
Output:
 
user142019
CH4 + O2 -> H2O + CO2
H2 + O2 -> H2O + CO
CH4 + O2
CCCC45C2
H2
C
 
Xeo
@WTP, that is literally the stuff from my first answer, eh?
 
user142019
Yeah, I found it on Google. :)
 
Xeo
@WTP Now add chemical rules so we don't need to write the rhs of > :P
 
1:06 AM
does anyone here know what a "static dll" is?
 
Xeo
I like my second version more, tbh. Looks way neater with "partial specialization" of the function
 
Also, make everything constexpr, dammit.
 
user142019
I'll also add ions tomorrow.
 
constexpr all the things.
 
user142019
It's 02:06 AM so I'll stop coding.
 
user142019
1:07 AM
brb on my iPhone
 
Xeo
lol, hi me!
2:07 AM, usually going online from my iPod when I go to bed :P
 
user142019
Back
 
user142019
Tomorrow all of my teachers go protesting against more working hours so I have a day free from school. :)
 
Why would he make compile time constants?
 
@user245823 a misunderstanding of how things work
 
1:10 AM
@DzekTrek Because I spent time doing it, and I don't want that work to go wasted.
 
user142019
I learnt many things about templates today.
 
Xeo
4
A: terminating function template recursion

XeoHere's one without a specific helper struct: #include <iostream> #include <tuple> template<std::size_t> struct int2type{}; template<class Tuple, std::size_t I> void print_imp(Tuple const& t, int2type<I>){ print_imp(t, int2type<I-1>()); std::cout <...

 
:) ok, but you can't force him to do something which will only harm his app, i.e. evaluation for particular invocation.
 
Xeo
I just found my best tuple printing code again
 
@RMartinhoFernandes , did you work on constexpr?
 
user142019
1:13 AM
C++ should really have compile time for loops.
 
No, I worked on making all his functions constexpr.
@WTP That's what the "indices trick" works around.
 
Xeo
Every iteration can be done by recursion IIRC
 
I see.
 
user142019
But for loops are often easier to understand, IMO.
 
Probably bias.
I think for loops are too low-level.
 
user142019
1:16 AM
However, "easy to understand" and C++ don't go well together anyway.
 
Xeo
Think so? I find our template wankery easy to understand. :>
 
user142019
Hey, I'm still a C++ noob eh :P
 
user142019
Gonna write a library for chemical stuff I think. Good practice.
 
Xeo
FUCK operator<< ERRORS!
 
user142019
Including all this crap!!1
 
Xeo
1:20 AM
They flood my whole screen, dammit
 
user142019
Buy a larger screen.
 
Xeo
Now I need to fucking pipe that into less -.-
Well, larger terminal
 
@Xeo typed << instead of >>?
 
2>&1 | less
 
Xeo
thanks...
 
1:21 AM
@RMartinhoFernandes |& less
on any decent/recent bash
 
Xeo
static constexpr unsigned size = std::tuple_size<Tuple>::value;
Errors on me.. wtf.
t.cpp:105:10: error: expected expression
  static constexpr unsigned size = std::tuple_size<Tuple>::value;
 
@Xeo Tuple is a typedef?
 
Xeo
no, template param
omg
I now know why the constexpr errored on me...
typeing [ instead of { sure sucks
damn German keyboard layout
 
hmm
can't get this silly web hosting to work :(
 
user142019
1:30 AM
Why not?
 
well, I'm using @Tony's web hosting for my domain
and supposedly, all you need to do to direct web hosting is change the name servers
but it doesn't quite appear to be enough
 
Did you wait until the change propagates?
 
@DeadMG out of context, I'm gonna blurt: Virtual Hosts and host header
 
and I don't even understand how it's supposed to work, because I never told my domain registrar what account to use on the target host
so how the fuck do they know that I intend to use Tony's hosting?
 
@RMartinhoFernandes You can always test the server by overriding DNS via /etc/hosts
 
user142019
1:32 AM
Clear your DNS cache?
 
@RMartinhoFernandes Yes.
 
@DeadMG Hostheaders alright (assuming HTTP)
 
no idea what that even is
 
It is a header that says whether you want to reach http://kittens.org or http://deadkittens.org, when both are mapped to the same IP adress
 
the problem is earlier in the pipeline than that
 
1:33 AM
So the server receives a request, gets the host header and forwards it to the right virtual host
 
the domain name isn't mapped to any IP
 
@DeadMG Used a CNAME?
Or did DNS registration not work?
 
well, they don't mention needing any CNAME
 
You don't need a CNAME. An A-record would be fine. However, what did you mean 'it isn't mapped to any IP"?
 
well, what I mean is, there's no way for the host site to resolve it to Tony's hosting
because I never had to tell the registrar who was supposed to be hosting it
and the host will only allow adding A-records to the existing domain, not my new domain
 
1:36 AM
You bought a new domain name?
 
@DeadMG Huh? If you know his IP adress/public domain name you can just point your domain name(s) at the same (IP: A record, domain name: CNAME record) and it will reach
 
@RMartinhoFernandes No, but it's a new domain name from the perspective of Tony's web host
 
Then Tony has to configure the server to recognize your domain name as a 'virtual host' (host headers). Or he has to give you access so you can configure that
 
I have access
nothing about virtual host
 
Xeo
Okay, wtf. I can't get my tuple printing code to work. my base-case isn't selected
 
1:37 AM
I'm assuming Tony knew what his account allows when he invited you to share his webhosting.
 
and I can't add CNAMEs or A-records to anything except subdomains
 
A lookup on wide-language.com yields no A nor CNAME records.
You need to set that.
 
@DeadMG Something about a webserver config?
 
yeah, I'm right there
@RMartinhoFernandes I got that far.
 
Xeo
Robot, help me.
 
1:38 AM
just no idea how
 
Xeo
What's possibly wrong with that?
I get an infinite recursion with Clang on that...
NEVERMIND, RARGH
fuck names.
There, I found a drawback to my "partial spec of function templates" workaround... -.-
 
aha, OK
I found the part where I add the A-records and shit
 
@Xeo int2type seems missing
 
@Xeo lol
@sehe Oh, I know that one from context. He got the function names wrong.
 
Xeo
1:41 AM
Yeah, compiles fine now that I renamed the base-cass function -.-
 
@DeadMG additions are mostly immediate. For modifications, allow for some time to propagate
 
right
so I just add a CNAME from my domain to Tony's domain
or an A-record with Tony's domain IP?
 
@DeadMG That would be most flexible - albeit slightly higher latency on first lookup :)
@DeadMG That is ok unless the IP address changes
 
Yeah, go with CNAME.
 
It comes down to whether you want to follow Tony's domain 'pointer'
 
Xeo
1:43 AM
> Because you're using C++98 (C++11 doesn't have this problem), you're invoking UB when you read a value from a union that was not the last value written in that union – Seth Carnegie 22 mins ago
Isn't it a problem in C++11 too?
 
CNAME records may only be used on sub-domains.?
 
@Xeo +1 my guess too
 
yes, it is
C99 changed the wording but C++11 did not
 
@Xeo Never checked, but I think it's still UB.
 
@DeadMG that could make sense. I don't remembher, really
 
Xeo
1:44 AM
Oh, so in C99 it's valid? What did they change?
1
Q: What does this C++ setter/getter pattern break?

Sam HocevarUsing the GLSL syntax in C++ I wrote custom vector classes such as vec2, vec3 etc. that mimic the GLSL types and look roughly like this: struct vec3 { inline vec3(float x, float y, float z) : x(x), y(y), z(z) {} union { float x, r, s; }; union { float y, g, t; }; union { f...

 
I don't think it's valid in C99 either.
 
Xeo
There, comment on the comment :P
 
@Xeo They changed it to implementation-defined behaviour, I think
or maybe it was a C11 change
but I know for sure that it's not UB in a C compiler compliant with their latest Standard
 
@DeadMG I have just checked, I don't currently hold any CNAME records for non-subdomains...
 
well, I used an A-record
it'll take a few minutes to propagate, right?
 
1:46 AM
@DeadMG: Ah. Found one with my other hosting provider:
vokalen.nl 	CNAME 	 	sehe.nl
You should be able to check that using nslookup/dig; It would appear to be a restriction of your domain registration manager
And this one looks close to the subject:
 
@Xeo Hmm, someone needs to know about the existing wheel that goes by the name of GLM.
 
*.zfs-fuse.com 	CNAME 	 	zfs-fuse.net
 
maybe it would be simpler to just go back to buying my own hosting from Dreamhost and only serve up static web pages :P
 
@DeadMG In that case, head over to AWS (EC2 supports serving static content just fine, and it will cost pennies)
 
is that the Amazon thing?
 
1:51 AM
Oh, he knows already.
 
well, I considered them, but after my fun with Windows Azure :P
I would have been fine with Windows Azure, but they had technical issues
 
fuuu
Amazon want my phone too! :( bitches
 
Seems to be standard practice...
 

« first day (467 days earlier)      last day (4481 days later) »