« first day (482 days earlier)      last day (4484 days later) » 

5:00 AM
Yea, without boost, please.
I know people love their libraries, but I just want to get a single -a or -m there.
 
Xeo
#include <iostream>
#include <string>

// name it 'hacker'
int main(int argc, char** argv){
  if(argc < 2){
    std::cout << "Usage: hacker [-a|-m]\n";
    return 1;
  }
  std::string first_arg(argv[1]);
  if(first_arg == "-a")
    std::cout << "automatic mode\n";
  else if(first_arg == "-m")
    std::cout << "manual mode \n";
  else
    std::cout << "error: unknown mode\n";
}
 
Thanks! gonna test this.
 
Xeo
Hm... something's wrong
 
I'm calling it ghost protocol, after Mission Impossible 4.
?
The dashes in the if statements?
 
Xeo
No, it's just Ideone that had some problems
 
5:05 AM
Oh, ok.
 
Xeo
Oh wait, it should rather be "Usage: hacker -a | -m\n", since the argument isn't optional
 
Finally got my complicated thread pool system to work
 
@IDWMaster Grats, although i have no idea what you're talking about.
 
It's a really big multi-threaded mess
 
@IDWMaster That sounds good. Starred.
@xeo - So once I'm reading in arguments, how can I get a value from them, like an input file name?
I see how you have an array, but let's say I wanted:
a.out -a -f "file.txt"
 
Xeo
5:10 AM
switch on each option, if it's -f, the next arg is the file name
 
oh, flags.
I see...
So it's a matter of tracking those things then.
 
Here's the code for the thread pool if anybody has a similar need to create one (author shows as webadm because that's my sign-in name to my computer):
http://pastebin.com/Eqv0AkHF
 
Also, @Xeo, Why are you returning 1 instead of exit(1)? Is there a difference?
 
Xeo
@Moshe We're in main, no need for exit
 
Ok
 
5:13 AM
@Moshe A thread pool is a collection of always-running threads which are available to queue tasks to so you don't need to keep creating/destroying threads manually. Basically automated thread management.
 
@Xeo, argv[2] is going to be the optional flag, if it exists, and then we need to check for an argv[3] which will be the name of the file?
@IDWMaster Ah, I see. In iOS we do something similar with table view cells to make scrolling faster.
 
Xeo
@Moshe Yes
But you need to strip it of quotes
 
@Moshe Does iOS come with a built-in thread pool system? Windows is sure way behind the times in their native APIs.
 
@Xeo Why start from 1 and not 0, btw? What's in 0?
 
Xeo
or just submit the filename without quotes
 
5:15 AM
@Xeo How so?
 
Xeo
@Moshe Either the program name or nothing
@Moshe I'm not teaching you programming here, it's a simple algorithm. :P
 
@IDWMaster There's something there, but I don't know too much about it. There's NSThread, NSPool, etc.
@Xeo Oh, I remember now.
There's a replace function.
 
@Moshe NSPool I'd bet
 
Wow, I'm stupid. cringes as he waits for the star
4
@IDWMaster There's a lot of stuff. On iOS we don't have garbage collection, so there's a lot of stuff related to that.
 
@Moshe So it could be a memory pool too. I also wrote a class for that as well.
That's what I'm using as the allocator->allocMem thing
 
5:18 AM
@IDWMaster Yup, we have a memory pool. but before the iOS 5 SDK introduced Automatic Reference Counting, there was manual retain/release counts.
We don't actually alloc directly because everything is pointers. I'm not so up on C/++ memory management. I use Apple's frameworks for that.
retain, copy, mutableCopy, new, alloc all require a corresponding release, autorelease
ARC has the compiler stick em in for you.
Well, enough about ObjC, I don't want it to land up in in the room subject.
@Xeo - I'm confused by your assignment/reading of first_arg. That's not an assigment. Looks like a function call.
 
Xeo
@Moshe huh?
 
@Xeo Shouldn't std::string first_arg(argv[1]) be std::string first_arg = argv[1];?
 
Xeo
No, why?
It's the same, nearly
 
Where's first_arg defined then?
 
Xeo
You should really read a book before dabbling in C++
6
 
5:22 AM
@Xeo I'm taking this class in Uni, but I haven't gotten the book yet. We're going really really slowly. I know how to program, but not in C++ - yet. The first semester was really simple. I'm obviously missing fundamentals. That's why I hang out here.
 
Xeo
@Moshe It's a call to the constructor, type name(args); is one form of initialization
For non-explicit ctors, it's the same as type name = arg (for one argument)
 
Oh, that's so cool. so I can just call a constructor with the type and it's a shorthand initializeation.
Sweet!
 
Xeo
No, it's a form of initialization, not a shorthand
 
@Xeo is on my "good list".
 
Xeo
5:24 AM
If the constructor is explicit, the assignment form won't work
 
I don't think it saves a single character
The = just looks like c-style
 
Xeo
struct X{
  explicit X(int){}
};

int main(){
  X x1(5); // ok
  X x2 = 6; // error: explicit ctor
}
 
@Xeo So if a constructor is marked explicit, you have to use that parenthesis initialization?
 
Xeo
@Moshe It really got nothing to do with "shorthand". Also, you can't pass multiple arguments through the assignment form
yes
 
Ah, I'm understanding a bit more now.
 
Xeo
5:26 AM
Marking it explicit bans all implicit conversions to the type.
 
@Xeo your saying has been deemed worthy enough to be added here
 
The copy initialization syntax (T t = foo;) is considered to involve conversion, whereas the direct initialization syntax (T t(foo);) is, well, direct initialization. A constructor marked explicit can't be involved in conversions.
 
Xeo
and = arg is a form of implicit conversion
 
... thinking about it... ...
 
@LucDanton Nor list initialization ≖⏠≖
 
Xeo
5:27 AM
@RMartinhoFernandes :'(
 
(what's a smiley for angry?)
 
>:(
≖⏠≖
 
≖⏠≖ <-- ???
 
@RMartinhoFernandes :wq
 
Xeo
@RMartinhoFernandes Wait. T t{foo}; is allowed. Did you mean void f(T); f({foo});?
 
5:29 AM
:angry:
 
Xeo
@Moshe Rather, :q! (angry quit)
 
@Xeo Well, :wq is the face I made the first time I saw vim.
 
@Xeo Yeah, the latter. I forget the names.
And ZZ is so much better than :wq.
 
hi, does exception handlers terminate the program ?
 
@RMartinhoFernandes and :wq makes for a funnier emoticon.
 
Xeo
5:42 AM
Okay, why the fuck does C++ select the (inaccessible) base-class constructor inside a template argument list here?
0
Q: C++ compiler error involving private inheritance

HighCommander4Could someone please explain the following compiler error to me: struct B { }; template <typename T> struct A : private T { }; struct C : public A<B> { C(A<B>); // ERROR HERE }; T...

 
Injected class names?
 
Xeo
But why a member function inside a template argument list? It just doesn't make sense...
 
Did you try clang?
Could be GCC using AES again.
 
Xeo
Nope, Clang spits the same error
> t.cpp:12:9: error: 'B' is a private member of 'B'
 
Does your solution work?
Not for me.
Oh, wait, I need to use ::B on both places.
 
5:48 AM
C(A) and C(A<struct B>) are two alternatives, aren't they?
 
No, I'm sleepy.
 
Xeo
@LucDanton Yeah
Btw, I was happy that Clang compiled C(A<::B>) :)
 
@Xeo Yeah, GCC compiles that too.
That is, as long as you save the file.
 
Xeo
lol
No, I meant because of <: digraph
 
Oh, that. I think GCC only disables trigraphs by default.
Ah, no, it warns.
This is completely nonsensical.
 
Xeo
5:52 AM
The choice of the ctor?
 
Xeo
Absolutely
 
@Xeo - So your constructors are cool, but completely crash if the value at a given argv index is null.
 
argv is never null.
 
Xeo
Unless you assign it
 
5:53 AM
If I don't pass in a third argv and and try to construct with it, what happens?
 
Xeo
@Moshe Well... then you accessed an invalid index
 
Right...
 
Xeo
argv[argc] is always 0
 
So I'm seeing this:
 
argc tells you how many arguments there are.
 
Xeo
5:53 AM
And is one past the end of the range
 
a.out -a -f
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
Abort
 
C(A<const B>);   // same error!
 
Xeo
Yeah, you can't pass 0 to std::string
 
std::string(nullptr) is indeed a crash. It's a bit silly, but sometimes you have to use std::string(foo ? foo : "") instead of std::string(foo)
 
5:54 AM
Ah, I can use ternary there. Sweet.
Yay! Thanks @LucDanton, so far so good.
 
C(A<B&>);   // same error!
C(A<B*>);   // same error!
// what the heck?
 
Ok, should filename go first or last in my list? And should it be optional?
 
Xeo
0
Q: Why does the compiler select the base class constructor inside the template argument list?

XeoFollow-up question to this one. Basically, in the following code, why does the compiler think that the B inside A<B> in Cs constructor refer to the (inaccessible) constructor of the B base class? struct B{}; template <typename T> struct A : private T{}; struct C : public A<B>...

This is really irritating.
 
$ cat test.cpp
struct B {
    B();
};
template <typename T> struct A : private T {};
struct C : public A<B> { C(A<B>); };
int main() {}
$ g++ test.cpp
test.cpp:1:10: error: 'struct B B::B' is inaccessible
test.cpp:5:28: error: within this context
It's not the ctor.
 
Xeo
@RMartinhoFernandes It is
 
6:03 AM
@Xeo Look at the line numbers.
 
Xeo
WTF
 
Yeah, no sense.
 
Points to line 1 because that's where B is defined.
 
Xeo
@LucDanton But, it says "B::B" in the error..
 
$ cat test.cpp
struct B {
private:
    B();
};
template <typename T> struct A : private T {};
//struct C : public A<B> { C(A<struct B>); };
int main() {
    B x;
}
$ g++ test.cpp
test.cpp: In function 'int main()':
test.cpp:3:5: error: 'B::B()' is private
test.cpp:8:7: error: within this context
It's not the ctor, I said.
 
6:06 AM
It take it that if someone's wondering "What? What B is this?" then the line number points to that direction.
 
lol, look at all the great sayings about java.
 
That's what a message point to the ctor looks like.
 
@RMartinhoFernandes Why?
Yeah, I think you put too much faith in GCC error messages. I wouldn't expect consistency for error messages across two similar yet different scenarios.
 
From the transcript, it seems all we do here is criticise java.
2 days ago, by R. Martinho Fernandes
I'm not sure what I learned from Java, other then "Java sucks".
 
@LucDanton lol
 
6:07 AM
Nov 27 '11 at 22:01, by Etienne de Martel
I leave the chat and people are talking about Java, I come back and people are still talking about Java.
 
@IntermediateHacker Yeah, I know, should be "than".
 
Dec 13 '11 at 3:53, by IntermediateHacker
is anyone here , who doesn't hate java?
lol...
 
I'm waiting for @Xeo to try with clang.
 
Xeo
t.cpp:1:8: note: member is declared here
struct B {
:(
 
I've never seen GCC to refer to a type as T::T to mean 'injected class name of itself' or some such.
 
6:09 AM
@Xeo Wait, it says "member".
Add a user-declared ctor.
 
@Xeo - It appears that I don't need to strip quotes.
 
Xeo
I can only imagine that it somehow refers to the base class subobject...
 
when I first read about GCC in a C++ article back when I was a newb, I thought the author was talking about this.
 
Xeo
@RMartinhoFernandes Where?
 
@Xeo Confirm if it's the ctor or not.
@Xeo In B.
 
Xeo
6:11 AM
struct B {
private:
    B();
};
template <typename T> struct A : private T {};
struct C : public A<B> { C(A<B>); };

int main() {
}
Is the test code
 
user868935
any way to read each word from a text file and put it's characters into an array?
 
@Luc see? Clang agrees.
:P
 
Xeo
And MSVC does too, btw. Not that anyone cares.
 
0
Q: Is there a cross platform way to clear the screen?

MosheIs there a cross platform way to clear the screen in C++? How would I do that?

 
6:14 AM
@Moshe Print a boatload of newlines.
 
Xeo
@Moshe We had that earier this week
 
Adjust "boatload" accordingly.
 
Xeo
Definitly a dupe
Sheesh, Nawaz' comments on my question..
Can't that guy see that I'm, like, totally repwhoring?
 
Xeo
12
Q: How do I clear the console in BOTH Windows and Linux using C++

srandI need a cross platform solution for clearing the console in both Linux and Windows written in C++. Are there any functions in doing this? Also make note that I don't want the end-user programmer to have to change any code in my program to get it to clear for Windows vs Linux (for example if it h...

One possible dupe
I'm seriously stumped.
 
6:17 AM
C++ stopped making the little sense it still made. What will be of my life now?
 
Xeo
Another day, another language quirk...
@RMartinhoFernandes You will switch to operate on Haskell
 
Oh, yeah, that reminds me, I need to install the super dupper new GHC.
 
Xeo
I'll ctrl-f the CWG defect list..
Okay, found the answer. :<
And it's actually in the standard
Maybe I should've looked through that first.
 
Well, I thought you were doing that.
 
Xeo
41 mins ago, by R. Martinho Fernandes
Injected class names?
The candidate gets 100 points
[ Note: In a derived class, the lookup of a base class name will find the injected-class-name instead of the
name of the base class in the scope in which it was declared. The injected-class-name might be less accessible
than the name of the base class in the scope in which it was declared. —end note ]
 
6:25 AM
Mmh, have to be careful, there's a distinction between std::tuple<decltype(expr)> and decltype(std::forward_as_tuple(expr)).
 
Xeo
[ Example:
class A { };
class B : private A { };
class C : public B {
  A *p; // error: injected-class-name A is inaccessible
  ::A *q; // OK
};
—end example ]
 
Super GHC is out?
 
@Xeo Woot, I have awesome hunches.
 
Xeo
So, want to post the answer?
 
@Pubby Comes in the Haskell Platform release next May, but it's already available.
@Xeo Ok, sure :)
 
@Xeo - Okay, so my program sorta works.
Except I forgot to account for outputting newlines to the console.
 
Is a conversion of the kind std::tuple<decltype(expr)> foo = std::forward_as_tuple(expr); ever invalid or surprising?
 
So it just outputs a huge blob.
 
Xeo
@LucDanton Depends on what is "expr"?
 
@Xeo Yeah, I'm relying on such conversions so far and I'm looking for pitfalls.
 
Xeo
6:29 AM
No, I meant, if it's a single function call, the tuple is obviously useless. :P
What do you put in there?
 
Why would you want to sacrifice conciseness in favour of representativity?
Adding ellipses everywhere doesn't make this any different.
 
Xeo
Robot, "note" not "not"
 
So yeah, my real code uses pack expansion, but it doesn't matter for the core of the problem.
Don't complain when people bring SSCEs :|
 
Xeo
@RMartino, use your edit grace period, or I will do. :P
 
Xeo
6:33 AM
And fix the quote
 
That typo is annoying because I can't :abbr it out and I'm constantly repeating it :(
 
Xeo
But I guess your edit period will be over by then
 
Damn, missed it by 6 seconds.
 
Xeo
Too slow!
:)
 
That DR is from 1999. I guess the note I quoted is the addressing of it?
 
Xeo
6:38 AM
Yes
 
Anyway, @Luc was right. GCC usually uses "X is an inaccessible base of Y" as error message.
 
7:00 AM
@Xeo - Here's what I have hacked out in vim over the last hour or so.
It's hanging while outputting the text, not sure why.
@RMartinhoFernandes You're welcome to look as well.
 
13
A: C++ I/O don't understand why there is -1

R. Martinho FernandesDo not read while not eof()1. That's not a proper reading loop. Read while reading succeeds. int x; while ((x = in.get()) != EOF) { cout << x << endl; } Testing for in.eof() will not guarantee reading will succeed. When you test for in.eof() you're actually testing if the pre...

 
Xeo
ooh, again?
12
A: Why is iostream::eof inside a loop condition considered wrong?

XeoBecause iostream::eof will only be set after reading the end of the stream. It does not indicate, that the next read will be the end of the stream. Consider this (and assume then next read will be at the end of the stream): while(!inStream.eof()){ int data; // yay, not end of stream yet, now...

I have one too!
 
@RMartinhoFernandes Doesn't make a difference.
 
Still freezes.
while(fileStream) isn't any better/
 
7:05 AM
@Moshe Welll, I haven't looked at it in depth, but I saw that in the loop, and that's practically always wrong.
 
I know, just added it as a last ditch attempt at failure.
 
user868935
anyone know how to read a file word for word?
 
Xeo
@Moshe, wait a second.. where are you even using the filestream in that loop?
            while(!fileStream.eof()){
                    std::string::size_type pos = chars.find("\n");
                    if(pos != std::string::npos){
                            std::string lineOne = chars.substr(0, pos);
                            std::string lineTwo = chars.substr(pos,chars.length()-lineOne.length());
                            std::cout << lineOne << std::endl << lineTwo;
                    }else{
                            std::cout << chars;
                    }
                    std::cout <<chars << std::endl;
 
It's reading from standard input only.
 
Xeo
No fileStream reference inside the loop
 
7:07 AM
@Xeo Whoops.
Good point.
It's 2 AM here. :-)
 
It's 7AM here.
 
Xeo
Also, please cut the std::endl and just use "\n", unless you really want to flush the stream.
 
Fuck, it's 7AM here.
 
Xeo
8am
 
user457812
Totally read that as "BAM" the first time O_o
 
7:09 AM
Lol
Hey, @nil.
 
user457812
Yo.
 
Xeo
Hm, lower-casing it doesn't really help, does it?
 
user457812
Not really. My glasses help, but I put them somewhere in my apartment and can no longer find them.
 
Xeo
> The goal is to use a tree to figure out if metaphorical dwarfs can pay their metaphorical taxes with metaphorical diamonds.
lol
 
@Xeo Oh, a Dwarf Fortress challenge.
 
7:13 AM
So now this prints, but looks like a blob.
 
Also, my distro is awesome: it has a Dwarf Fortress package.
 
Xeo
Well then, I'm off for the next few hours
 
Bye. Sleep well.
 
@RMartinhoFernandes - So how do I preserve line breaks when printing to standard output from a file stream?
@nil - how's for some blind debugging?
 
user457812
Definitely not interested
 
7:17 AM
lol
 
@Moshe Either you read line-by-line (with std::getline), or in binary mode. Otherwise the linebreak information is lost.
 
binary mode?
 
Sorry, I meant unformatted input.
The istream::read member function.
 
Better, now, with get line, but still broken. Shows tabs, but not newlines for some reason.
 
You need to insert the newlines back by yourself.
 
user457812
7:23 AM
Why can't I kick people in the face over the internet yet? It's 2012, I should be able to do this by now.
 
getline discards them.
 
@RMartinhoFernandes Oh... I think I knew that.
that sucks.
Well, not a biggie.
Ok... closer to working
Logic error.
 
So, I have (arg1 && false)(lvalue) not working but (arg1, false)(lvalue) working. I guess that's another GCC mangling issue?
 
7:39 AM
C++ is a mangled language
2
 
I can't argue with that.
The difference might be explained by what return lhs, rhs; does actually.
 
user457812
Wouldn't that just return rhs?
 
user457812
Pretty sure the comma operator works that way, any who.
 
Well, I could do more tests with other equivalents to arg1 && false that are not arg1, false.
(This being called with an std::string.)
Wait, how is some_lvalue_string && false going to work.
I found the problem! It's me!
9
 
@LucDanton if arg1 is what it usually is (a Boost Phoenix placeholder), you'd get phoenix operator,, avoid it with
 
7:46 AM
Man, no wonder Haskell has const, that's much less round-about/hack-ish (const false being the equivalent of arg1, false here).
 
sbi
room topic changed to Lounge<C++>: I don't want it to land up in in the room subject. [c++] [c++11] [c++-faq]
 
 (arg1, void(), false)
 
@sehe No, I don't want to avoid it. That's kinda the point.
How is find_if(tuple, false) going to work you silly goose?
 
@LucDanton I use (False!) for that, with (!) = const. Abusing sections for unary operators is cool.
 
@sehe Also the correct syntax for that is void(), not (void).
@RMartinhoFernandes Any reason you picked postfix ! for that?
 
7:48 AM
@LucDanton cheers. I got the idea at least :) What overload of find_if takes a tuple and a value? Perhaps I was missing the big picture.
 
I don't think I'm familiar with such a meaning for !. Is that because you really, really want to return False?
 
@LucDanton Because C++ doesn't have it? Erm. Colour me confused
 
@LucDanton No, it's just the notation we used in class.
 
"False! I mean it!"?
@RMartinhoFernandes I see. I like my 'explanation' still.
@sehe The one I'm implementing right now! I've written some algorithms for tuples already and right now I'm going overboard with find_if.
I'm going to scrap it, was fun to implement but who's going to need it really.
 
Wait, how is that going to work? What's the return type?
 
7:50 AM
@LucDanton Doing boost fusion over again (in c++11 style, I reckon)? :) Next time, add a little more context:
12 mins ago, by Luc Danton
So, I have (arg1 && false)(lvalue) not working but (arg1, false)(lvalue) working. I guess that's another GCC mangling issue?
 
optional<typename make_variant_over<mpl::vector<T...>>::type>
(Well it's not exactly T... but to cut a story short.)
 
Was kinda hard (read: impossible) for me to see that you posting parameter lists to find_if?
@LucDanton You need to borrow Andrei's ellipsis key
 
But in C++ it's still 3 plain old da's :(
One key to input three characters? Madness!
 
7:52 AM
Use a different font.
 
@sehe That's exactly it, yes. Although thanks to C++11 facilities, a hypothetical pure C++11 Boost.Fusion would be much, much more compact than the current version.
 
Ok, acceptable for tonight.
 
(Although if I keep adding silly 'algorithms' it won't be that much more compact, hah!)
 
@LucDanton More compact is good. I know the pain I went through adapting std::tuple to it.
 
@LucDanton something like :inoremap ... <C-k>.:(roughly :iabbrev ... ∴) (can't find a digraph for true ellipsis right now)
 
7:56 AM
You mean the other way around right?
 
I keep reimplementing some Boost features for the reason that perfect forwarding makes it painless and allows me to use move-only types. And as an added benefit, the result is quite compact.
 
Yeah, boost is still lacking in the move department.
I wonder if 1.49 will have moves galore.
 
@LucDanton I reckon that goes for about 60-70% of boost (MPL? And think about the proliferaction of boost RESULT_OF etc.)
@RMartinhoFernandes That's already done...? boost/fusion/adapted/std_tuple.hpp from memory
 
So far that's bind (arguably almost a re-done std::bind, not so much Boost.Bind), named parameters, optional, expressions (instead of Boost.Phoenix), unique_function (more of a side addition to std::function than a replacement), and those tuple algorithms.
 
@RMartinhoFernandes, @LucDanton - This version prints line by line, but it's supposed to do chunks of characters. Any idea why?
 
7:58 AM
@LucDanton Submit the ideas! Usually well received. Usually, you can make things optional for c++0x challenged platforms:
#ifdef __GXX_EXPERIMENTAL_CXX0X__
    #define BOOST_RESULT_OF_USE_DECLTYPE
#endif
e.g.
 
@sehe Wait, what? Now I'm not really sure when it was I did it, but I hope this was not in 1.47.
 
@Moshe Linebuffering
 
@sehe Not sure how to go about it. So far I've been using GCC snapshots which make my code break each time I upgrade. I'd at least like to have Clang compile my code before doing anything important with it.
 
@sehe ?
 

« first day (482 days earlier)      last day (4484 days later) »