« first day (543 days earlier)      last day (4388 days later) » 

8:02 PM
how do i initialize a double vector to all -1s
vector< vector<uint64_t> > memo(a, vector<uint64_t>(b));
 
@jalf here you go:
0
Q: QTableModel does not seem to show on a QMainWindow

NealHere is my code for my MainWindow: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QSqlDatabase connection = QSqlDatabase::addDatabase("QMYSQL"); connection.setHostName("localhost"); connection.setDatabaseName("dbname"); connection.setUserName("username"); ...

 
sbi
@JohnSmith There's no double in there.
 
vector<vector<uint64_t>> x(n, vector<uint64_t>(m, static_cast<uint64_t>(-1)));
 
@Neal do you add it to the window somehow?
 
@daknok_t yes
 
8:05 PM
@sbi He means double as in nested.
 
I added it to the view
 
i am trying to write a sort of memoization
 
sbi
@GManNickG Yeah, I figured that out after you posted your reply.
 
a vector that stores int64's
takes in two input ints, a and b
 
Sounds like you want std::map<std::pair<uint64_t, uint64_t>, R>
 
8:08 PM
sorry what i mean
is that i have a function, f(a,b) where a and b are ints
and the output of f(a,b) is an int64
so I want to be able to store f(a,b) into a memo structure and be able to retrieve the value later if I call f(a,b) again
 
So then std::map<std::pair<int, int>, int64>
 
use the standard long long instead of the nonstandard int64.
 
long long isn't long enough
 
:-(
 
@JohnSmith then neither is int64, since long long is 64 bits
 
8:10 PM
or at least, it gives me overflows all the time
for some reason uint64 does not
 
@JohnSmith unint64's standard name is "unsigned long long"
 
@MooingDuck uint64_t is Standard.
 
@JohnSmith that u is important, doubles the range of valid positive values.
 
Or std::uint64_t if you will.
 
8:11 PM
so if I am using std::map<std::pair<int, int>, uint64_t> how can I check if a value exists
and if not, store it?
 
@LucDanton didn't know that
 
@MooingDuck That's not true.
 
like if I am declaring this thing from the start is it all init to 0?
or is it all null?
 
@MooingDuck <stdint.h>/<cstdint>
 
unsigned long long has a range at least that of std::uint64_t, but may have more than 64 bits.
 
8:12 PM
@JohnSmith if (mymap.find(std::make_pair(a, b)) != mymap.end()) ...
 
is .find() a lengthy procedure?
 
@JohnSmith log(n), so not really
 
okay, going to try this out
 
@JohnSmith if you have a billion elements, it will compare about 30 of them.
 
so I don't have to initialize size at all? I can use do std::map<std::pair<int, int>, uint64_t>
and then use your find function, and store that way?
 
8:14 PM
@JohnSmith yup, maps add space as needed automatically, don't worry about size
 
maps are my favorite stl data structure
 
@Collin I like vector, but map is pretty awesome
 
@MooingDuck I use vector more often, but like map more.
 
@JohnSmith inserting into a map is mymap[std::make_pair(a,b)] = my64_value;
 
sorry i don't know how this is used actualyl
i want to say "if a and b exist in memo (the name of the map)
return the element
 
8:15 PM
map_type::iterator it; if((it = map.find(std:make_pair(a, b))) != map.end()) { return it->second; } else { auto value = compute(a, b); map.insert(std::make_pair(std::make_pair(a, b), value)); return value; }
 
yeah, that's what @MooingDuck 's little snippet does
 
 auto i = memo.find(std::make_pair(a,b));
 if (i != memo.end())
    return i->second;
 else
     ????
 
Better copy that and format it somewhere.
 
else store the element after doing the processing
 
@LucDanton why not make that multiline? I can barely read that
 
8:17 PM
@MooingDuck There's also a map.insert. It can be faster if what's being stored is slow to default construct and/or assign (admittedly, not the case here).
 
@MooingDuck Takes too much screen estate. The needs of the many etc.
 
@JerryCoffin but it takes a pair and I always found that confusing
 
what is map_type
 
I'm assuming that the map in question is declared as map_type map; somewhere.
 
whatever you did with map<pair<int, int>, uint64_t> - ish thing
preferably something like typedef map<pair<T,T>, uint64_t> MemoMap;
 
8:19 PM
it's not liking map::iterator it;
 
@MooingDuck value_type is std::pair<const key_type, mapped_type>. Would that help?
 
@MooingDuck I'm not sure if it's really very confusing, but I do probably use the subscript operator to do insertions at least 90% of the time.
@JohnSmith Given the map_type elsewhere, you'd also need map_type::iterator.
 
@JohnSmith map<std::pair<int, int>, uint64_t>::iterator
 
i don't see map_type elsewhere
 
@LucDanton I know how, it's just confusing and I don't like it.
 
8:20 PM
@JohnSmith You would have had to typedef something to map_type for it to exist
 
@Collin you guys have completely lost him :D
 
no i got it i think
 
@MooingDuck Use a sorted std::vector<std::pair<key_type, mapped_type>> + std::lower_bound once or twice and you're set for life!
 
except it dislikes auto value = f(a,b);
ISO C++ forbids declaration of `value' with no type
 
That's for C++11.
 
8:21 PM
@MooingDuck I'm pretty good at driving people off the deep end
 
can i just change it to a standard uint_64?
uint64_t value = f(a,b) ?
 
assuming f returns a uint64_t, yeah
auto just figures out what type something needs to be, you can always specify it yourself
 
...i think it's working?
but i have no idea
 
@LucDanton I have a class that does just that. It's speeds are counterintuitive compared to map in my tests though. Never did figure out why.
 
@JohnSmith This describes how I feel about all code I write
 
8:23 PM
lol
 
@JohnSmith debug it. Step into the code. Be one with the code. You are the code.
 
Been doing some WPF + C# lately, It seems to work, but for all I know it's chock full of horrible race conditions and will break the moment I try to give it to someone important
 
I am Neo now eh
 
Do I get to know kung-fu?
#include <evil sentient overlords.h> //fuuuuuuuuuuuu---
 
8:29 PM
How 'bout a more cleanly formatted, more complete version of the sample code:
typedef std::pair<int, int> key_type;

typedef std::map<key_type, uint64_t> map_type;

uint64_t memo_f(int a, int b) {
static map_type map;

map_type::iterator it = map.find(std::make_pair(a, b));
if (it != map.end())
return it->second;
uint64_t value = f(a, b);
map[std::make_pair(a, b)] = value;
return value;
}
 
Only thing I would do is keep std::make_pair(a, b) as a variable, to avoid repeating it.
 
Fair enough:
#include <map>

typedef std::pair<int, int> key_type;

typedef std::map<key_type, uint64_t> map_type;

uint64_t memo_f(int a, int b) {
static map_type map;

key_type key = make_pair(a,b);

map_type::iterator it = map.find(key);
if (it != map.end())
return it->second;
uint64_t value = f(a, b);
map[key] = value;
return value;
}
 
And there goes the screen real estate.
 
key_type key(a, b) :P (Obviously just being annoying now.)
@LucDanton: This isn't 1980 anymore.
 
@GManNickG I know. My two other screens are fine. But this isn't about me.
 
8:33 PM
@LucDanton So tell the others to follow suite! :P
 
@LucDanton I've heard too many bars nearby can devalue property, but it wasn't 'til just now that I realized how much less valuable screen real estate is because of scroll bars!
 
@GManNickG I'm at work, so I have to keep the SO window small so I can work with the rest of my screen :(
 
@JerryCoffin Might want to replace map[key] = value with map.insert(it, std::make_pair(key, value)).
 
@GManNickG why? It shouldn't be any faster, and it's harder to read
 
@GManNickG find will have returned end() in this branch.
 
8:35 PM
@_@
which version is best to use now?
 
There I go being stupid again.
 
@GManNickG I just mentioned that a few minutes ago. I see no gain in this case.
 
except with indentation
 
@JohnSmith For the most part, there's little practical difference between the two -- I just added enough extra "stuff" that it should compile pretty much as-is instead of needing you to fill in a lot of blanks...
 
How does one make a question as a favorite?
 
8:39 PM
@Robᵩ There's a star under the area where you vote on it.
 
ahh
 
@GManNickG - Thanks.
 
is there some weird way C++ handles negative numbers and modulus
like i have (a-b) mod m that gives the right answer
but a mod m - b mod m all mod m gives wrong answer
because a mod m is smaller than b mod m
 
@JohnSmith Yes and no.
 
sbi
The last three tweets are brought to you by five hours of frustrating debugging last night.
 
8:44 PM
The reason I say that is that C++ doesn't have a modulus, it has a remainder. That acts like modulus for positive numbers, but not for negative numbers.
 
so how can i change it?
so it correctly calculates
 
@JerryCoffin I thought its behavior for negative numbers was implementation-defined?
or did they nail it down in C++11?
 
If memory serves, something like a = b % c; if (a < 0) a += c; should get you what you normally expect as a modulus (but keep in mind that if you do, it won't pair correctly with a/b anymore.
 
@jalf Yeah.
 
yeah i literally did just that
if the number is negative, add the modulus to it
 
8:49 PM
@jalf I think they did, anyway. It was nailed down in C99, and I think C++11 adopted the same rules.
Yes, doing a quick check, / is now required to truncate toward zero, and (a/b)*b + a%b == a. (§5.6/4, if anybody cares).
 
> bound_with_cv_of<RemoveReference<RemovePointer<RemoveReference<C>>>>::template apply
Is there any way to format that with a nice result lol?
 
@LucDanton maybe if your editor supported a white on white format? Not exactly nice, but at least hides the ugliness...
 
Needless to say this appears in a detail namespace.
 
@LucDanton Thank goodness!
 
9:11 PM
In fact this line appears in what I think is the ugliest 'plumbing' helper class I've ever written.
I don't usually write partial specializations over several lines like that.
 
@LucDanton Code like that gives me more sympathy for people who hate C++. I don't mean that to be nasty, because I sure don't see any obvious improvements, but lord that's ugly!
 
It pays its dividends when unique_function<T(U, V)> f = &foo::bar; compiles even when foo::bar is overloaded!
Admittedly it won't catch all such instances but ah well.
 
@LucDanton Yeah -- as least as far as hating C++ goes, the other side of it is: "Can you name an alternative that does the same thing cleanly?" Unfortunately, the usual answer is "no, not even close" (though for some things, probably including this, Haskell can almost certainly be cleaner).
 
@JerryCoffin On the other hand I just came up with the line and it worked right almost right away with just a few tweaks. Perhaps some other day I could find a superior (in terms of niceness) alternative. In fact the offending line would look better if I had a MPL-style protocol: with_cv_of<Cc, _1> (where Cc is the long-winded stuff that remove references and pointers).
Oh wait that 'on the other hand' seems misplaced now hah.
In any case the important bit is in the actual use site, where it looks like using member_type = Invoke<detail::to_pointer_to_member<private_type, Ret(Args...)>>;. I feel like if I could have got rid of that private_type the intent would be perfectly clear. If that's the price to pay for that is that the specialization looks wild I'm sort of Ok with it.
 
@LucDanton If it didn't sound so conceited, I'd say something about great minds thinking alike.
 
9:24 PM
Eh, I'm renaming that plumbing to_member_type.
 
for once, I need to get some sleep- some proper sleep
nighty night nubcakes
 
9:52 PM
Nighty.
 
Hmm, is a dynamic "array" actually an array or not? I don't think one can get a reference to it...
I think it is, but you simply can't get a reference to it.
 
It is. I'm torn on the second part though.
 
Yeah, I think it has to be since it stores the length information and destroys it's elements and such. We only get a pointer to it's data though, no way to get at the array itself.
Weird.
 
@MooingDuck: Yes, it's an array. The new expression itself only returns a pointer to the first element, though.
 
@GManNickG wait, but that "array" has no type. Or maybe it's like a runtime type? No wonder I can't get a reference to it. No compile-time type.
 
10:02 PM
It has a type, but not necessarily a type you can express at compile-time. Think of things like the dynamic type, type-erasure etc.
 
@LucDanton ah, that makes sense. Each could be expressed as a int(&)[12] (unknown at compile time), but then comes the type erasure to a int*, makes sense.
 
I still would like a way to go from an element of an array to the array itself, and in the same vein a way to go from a member/subobject to the enclosing object. Things like offsetof & friends, but less error-prone and for more than just Standard-layout.
 
DUH!
3
A: QTableModel does not seem to show on a QMainWindow

alexisdmAccording to the code you posted, you didn't open the database connection. QSqlTableModel doesn't open it for you.

 
@LucDanton I can't think of a way to design that. Given an int prove it is a member of a array/object. I don't think it can be done.
 
@LucDanton: I.e., not have crappy C-style arrays. :)
 
10:08 PM
@MooingDuck It can (in the array case), but it's awkward. But that doesn't matter, even if you do know the object is an element/subobject of an enclosing array/object you can't get back to that object in the general case.
 
@MooingDuck: I think he means: int i[] = { ... }; auto& j = i[4]; i.offsetof(j); // returns 4
UB if the argument passed to offsetof is not a member of the array.
 
@GManNickG but that's trivial for arrays.
 
@MooingDuck But the point is to not have to type/implement it. :)
@RMartinhoFernandes: How often do you update that standard draft revision?
 
@LucDanton I thought you meant "given an int* or int& or something, return the array it's an element of", which would be impossible.
 
hello
 
10:16 PM
hi
 
@MooingDuck It is, and you can get a reference to it, though it's not easy to do (and usually kind of pointless):
#include <iostream>

int main() {
static const int size = 10;

int *f = new int[size];
typedef int (*p)[10];
int (&array)[10] = *reinterpret_cast<p>(f);

for (int i=0; i<10; i++)
array[i] = i;

for (int j=0; j<10; j++)
std::cout << f[j] << "\n";
}
 
@MooingDuck Consider that given struct base {}; struct derived: base{}; and a pointer base* p; where *p has dynamic type derived, then static_cast<derived*>(p) points to the object to which *p belongs. But you can't do that for members or elements of an array.
 
@JerryCoffin reinterpret_cast is kinda cheating :P
@LucDanton right, it can't be done in the general case. Obviously you could make a specific element type that was able to, but can't be done_all_ element types.
 
@MooingDuck If you really prefer, you could use a C-style cast.
 
how can i install a big number library?
 
10:20 PM
@JohnSmith Which step has you hung up?
 
I am looking into this GMP library but the instructions don't make much sense
 
@JohnSmith are you on a linux system?
 
Windows
 
@JohnSmith The easiest to install (in my experience) has been Victor Shoup's NTL. Pretty much just install, point your include variable at it, include the right header, and go. GMP on Windows is much more difficult (to put it nicely).
 
@JohnSmith exciting. Did your GMP come with .c files or a .so file?
@JerryCoffin is that header-only?
 
10:23 PM
Looking into NTL now
so all i need is #include <NTL/ZZ.h>?
 
@MooingDuck I can't remember for sure any more. If I had to build anything, it must have been pretty quick and easy, because I don't remember doing much.
 
Just to make sure I'm not being an idiot again: when I define a move-constructor, the copy-constructor should no longer be implicitly created, right?
 
@JerryCoffin judging by the comments, you have to link against a library.
 
As in struct foo { foo(foo&& other){} /* no copy constructor! */ };
 
@GManNickG I don't know, just delete the copy constructor :(
 
10:26 PM
@MooingDuck Yup, looking at it, it looks like I did build a library. Must have built pretty painlessly though, because I don't remember doing it.
 
Er this still looks kinda complicated
 
@JerryCoffin I can't tell from the instructions if you build it yourself or not
 
@GManNickG Yes.
 
@JohnSmith easier than GMP
 
Yeah I am reading that GMP is "a pain in the neck to get working on Windows"
 
10:27 PM
@MooingDuck I have a bunch of object files, so it looks like I did.
 
hi guys, is there anything special about member function or variable pointer that I can't do it using just normal pointer to a function or variable inside the class itself ?
 
@LucDanton So you mean to say this random error I've been having lately is yet again not my fault, but the fault of MSVC calling a copy-constructor that shouldn't exist? Golly gee. Hey MSVC, I wrote that move-constructor for a freakin reason.
 
@AlexDan Yes. You need a pointer to a member, which is an entirely different sort of beast (and using it isn't the same either).
 
@JerryCoffin Are you sure? "A pointer to a standard-layout struct object, suitably converted using a reinterpret_cast, points to its initial member" applies to class types. I'm having a hard time finding such a guarantee for e.g. standard layout types.
 
@GManNickG what about the assignment/move assignment. Get those too
 
10:29 PM
@LucDanton Well, yes, there are a few specific circumstances under which you can convert one to the other (but not many).
 
@JerryCoffin Can't find anything regarding standard-layout types or layout-compatibles types that applies. Where to look?
 
a hoy
 
I never had any problem with GMP on Windows.
 
simple question, if I have struct myStruct {int * a }; and want to set the value of what a points to (assuming I has been set to something valid) would I need to write *(myStructInstance.a) = 10
 
10:32 PM
@thecoshman yes
 
Urd?
That Orcish?
 
hmm... so I am doing something else wrong :P
 
@CatPlusPlus mp: my fingers shifted right one key
 
@MooingDuck Chup chup. Going to have to explicitly disable the copy-constructor, bleh. I expect my code to work when it's correct!
 
@CatPlusPlus IIRC, it's pretty easy with CygWin but hard with MinGW (or maybe vice versa) and essentially impossible with VC++ (or anything that's not based on gcc). I think it's supposed to be a bit easier now than it used to be though.
 
10:34 PM
Again, had no problems with either MinGW or VC.
You'd probably want MPIR anyway, because they care bit more, but still.
 
@CatPlusPlus Really? With VC? Things have definitely changed in that case. I worked at it for quite a while, and never succeeded, and only gave up after reading quite a few comments saying nobody else had done it either.
@LucDanton I don't think there's any such guarantee except for standard layout (or, in the old standard, PODs). No amount of looking will do any good, because it just doesn't exist.
 
gmplib.org/list-archives/gmp-discuss/2008-April/003101.html "Today we can announce an agreement between Swox and Microsoft that will make future GMP releases much more easily accessible for users of Microsoft(tm) Windows(R) Visual Studio(tm)."
 
@JerryCoffin The guarantee I'm looking for is for standard layout.
 
@LucDanton I thought you just quoted it. In any case, §9.2/20.
 
does C++ allow flexible arrays as the last member or not? I can't recall
 
10:43 PM
@JerryCoffin No, that's for standard-layout structs. In your case an array of int is involved.
 
@MooingDuck Ah, that would probably be about 4 or 5 years after I tried. Maybe even a bit more...
 
any hoops, I can sleep easy now I know am still able to use C++
night all
 
night
@MooingDuck Not since I last looked, C++11 may have made it okay but I doubt it.
 
Hmm, Armadeep left a comment on my answer "I learned to never answer array questions years ago. No matter if what you say is useful, somebody will always be there to downvote it.". He's totally right. :(
 
Can anyone with VS11 check if this fails to compile (as it should)? ideone.com/Ul1NK
 
10:49 PM
@LucDanton Oh, sorry, we're back to that! I thought we'd moved on. In this case, we're casting the pointer to its actual type, which is covered by §5.2.10/2.
 
@JerryCoffin The type of the expression f is int* ;)
That paragraph is for identity conversions.
 
@LucDanton What's the question?
 
Where is the guarantee that you can convert from a pointer to the first element of an array to a pointer to the array itself (with suitable element type, if/when applicable)?
Problem being that there are a lot of concepts that criss-cross and I don't find it obvious where to look: reinterpret_cast, pointer conversions, standard layout types, layout-compatible types?
 
So we want to know if this is okay: int a[3]; int* p = a; reinterpret_cast<int(&)[3]>(p);?
 
Yes. Relevant message (and follow-up) that triggered interest.
 
10:59 PM
It's annoying when people post a comment on your answer saying it worked and answered the question, but don't accept the answer
 
@LucDanton: I'm going to say it's okay, quoting my feeling like it should be and bleh.
 
@GManNickG Unfortunately it's a quote I'm after.
 
@LucDanton I just quoted myself, what for do you want? :)
> GMan says it's okay.
See.
 
Sounds legit.
 
Okay, for my updated interpretation of the question, §5.3.4/2 seems relevant. §5.3.4/5 confirms that in something like new int[10], the allocated type is an array. Subsequently, it talks about "If the allocated type is an array type", which seems to confirm that what's allocated is/can be an array.
 
11:06 PM
I agree.
 
One hour left to get 5 rep to get 200 rep today :(
 
@SethCarnegie: Enjoy your 10 rep., you're welcome.
<3
 
Yay thanks
 
20 for good measure.
 
Yeah, I gotta keep reminding myself to upvote people past 200. Since you can't see if they casted any downvotes...
 
Only got VS2010... :(
 
@GManNickG me too
 
I am disappoint.
 
@GManNickG It compiles without errors.
 
@JerryCoffin Thanks.
Heh, so they closed it as By Design for 2010, then never fixed it for later releases. connect.microsoft.com/VisualStudio/feedback/details/586332/…
 
11:48 PM
@GManNickG Being fair to them, the list of conditions under which a move ctor is generated automatically was being changed up until pretty shortly before the standard was finalized. If they had fixed it to follow N3092 (i.e., what was discussed in the linked post), it would still be wrong now. The list of conditions eliminating auto-generation of a move ctor expanded from 2 items in N3092, to 5 items in the standard.
That does fit pretty well with how MS has historically done their compiler development: most releases make only very slight improvements in conformance, then they do a release (as often as not, with a minor version number change) that makes a huge improvement -- then back to a few years of nearly no change.
 
Where in the cycle are we right now?
 
@LucDanton we recently got rvalues and (supposedly) the entire standard library
 

« first day (543 days earlier)      last day (4388 days later) »