« first day (261 days earlier)      last day (4670 days later) » 

12:59 AM
2
 
 
6 hours later…
7:10 AM
Hello, hello.
 
8:08 AM
Whoa!
@jweyrich: Totally awesome link/articles.
 
Can anybody help me understand what some c++ code does?
 
Go on :)
 
/// sparse_matrix_traits<> generic version:
template <typename M>
struct sparse_matrix_traits
: sparse_matrix_detail_traits <typename boost::remove_const<M>::type, M>
{
// typedefs:
// matrix_structure
// storage_format
// ordering_type
// value_type
// value_pointer
// index_pointer
// enum (or static size_t const):
// index_base
// static functions:
// index_pointer index1_storage()
// - compressed column: array of column start locations
// - compressed row: array of row start locations
I'm not quite sure what the ":" does :-)
 
It's inheritance
 
So what is deriving from what?
 
8:21 AM
sparse_matrix_traits derives from sparse_matrix_detail_traits <typename boost::remove_const<M>::type, M>
 
Why would the programmer write a derived class with no content?
The child seems to be empty...
 
I don't know if the functions belong to the base class or have been commented out
I think it's just because it's simpler to write sparse_matrix_traits<M> than sparse_matrix_detail_traits <typename boost::remove_const<M>::type, M>
 
You wouldn't have happen to know how to use any of linear algebra stuff in BOOST would you?
eh?
 
Unfortunatly no
 
Umf!
oh well thanks for the help
this library is madness
size of the struct is zero when declared.
 
8:29 AM
Morning
 
:-/
 
@FredOverflow Thx, I think I asked this before, but cannot find any question on SO
 
@Misha It's normal, this struct only contains typedefs
Oh well, he's gone
 
@Misha What do you want to do with matrices?
 
8:54 AM
Doesn't size of an empty class == 1?
 
@CatPlusPlus Indeed.
That's what he meant I think.
 
Why can't it have size zero?
 
9:12 AM
The real reason is that each and every one object of a type must have a different pointer from other objects of the same type.
Simplest thing that works is making them size 1.
 
Is the size mandated by the standard, or can an implementation make them size 0, and do shenanigans to address that pointer constraint?
 
Only the address stuff.
I suppose you can also never take an address, turn up the optimizations and inspect the generated assembly. That's why sometimes it's recommended to pass empty types by value.
 
So, an object's address is the C++ notion of object identity?
 
Type is also important
struct empty_base {}; struct derived: empty_base {};: derived can be of size one
And the empty_base subobject of a derived can share the same address as the most derived object
So given a void* you can potentially have the same value but different objects
 
I always forget about inheritance.
 
10:16 AM
> A random_device uniform random number generator produces non-deterministic random numbers.
lol.
 
Docs from where?
 
Well, that's optimistic
 
At least it doesn't explicitly say that the others produce deterministic random numbers.
@LucDanton Why?
 
@MartinhoFernandes I'm checking my copy of the draft to get more context
 
10:21 AM
In systems where you have entropy easily available (like /dev/random on Linux) it's feasible.
 
I do notice that right after your quote there is a relaxation on the requirement :)
 
And it allows implementations to fall back on PRNGs on systems where a real RNG is not available.
@LucDanton Yes, exactly.
 
That's what I wanted to check -- how binding/constraining that was
and also I'm trying to remember how the device fits into the whole engine - distribution shebang
 
It conforms to the necessary requirements for the soon-to-be-usual bind(dist, engine) thingy.
There's one thing I don't understand: what's the param_type for in distributions?
(Table 118)
All distributions seem to define it as typedef *unspecified* param_type, which doesn't help a bit.
 
Check the requirements for distributions
 
10:29 AM
Seems to exist so I can pass it to other instances of a distribution type, so they behave the same.
I don't understand why not just use the copy constructor.
 
There's also a strong requirement that if D(a0, ..., an) is valid for constructing a distribution it is valid for constructing a param, i.e. D::param_type(a0, ..., an)
Presumably it allows stuff like easy emplacing of distributions from a single param, which may be more convenient.
 
Ah, that's probably it. Thanks.
 
It makes it more easy to write lazy code I'd say
Weirdly enough wouldn't it possible for D::param_type to be D itself?
I was going to say: "after all, for things like a Gaussian distribution, wouldn't it make sense to work on the parameters themselves without any intermediary computation?"
then I realized I'm not a numerical analyst
So... laziness is a virtue!
 
@LucDanton I think so. It would make the ctor that takes a param_type into the copy ctor, which are suspiciously missing from the distributions :)
Or should that be :(?
 
Well, it allows implementors to separately store any intermediary computation they can use in a distribution object. 'Caching' those computations can make for a more aggressive operator().
Or are you asking if default distributions are required to be copy constructible?
 
10:39 AM
They are.
> D shall satisfy the requirements of CopyConstructible (Table 21) and CopyAssignable (Table 23) types.
But the synopsis of each of the standard distributions does not include a declaration of the copy ctor.
That isn't something that is usually elided in the standard, right?
 
I don't know how it works here: are the synopsis meant to be binding pseudo-code (i.e. what is not described is not guaranteed to work) or more closely reflect actual code (i.e. the copy constructor is the implicitly declared one)
 
Oh, yes, there's the implicit one. Stupid me.
 
Also the param constructor is explicit.
The libstdc++ choice is to have a separate public type for the param type
 
Doesn't seems like something I'll be using lots. But it's good to know it's there.
Ah:
> Descriptions are provided in this section 26.5.3 only for engine operations that are not described in 26.5.1.4 or for operations where there is additional semantic information. In particular, declarations for copy constructors, for copy assignment operators, for streaming operators, and for equality and inequality operators are not shown in the synopses.
 
The proverbial details.
 
10:53 AM
And there's a similar notice atop the distributions section.
 
First time in chat. Some time ago posted an answer to a question, and received some doubtful comments from Konrad in the comments. I would like to know if my answer is correct, but haven't gotten a response to my comments. Hoping the Gurus here can help. (stackoverflow.com/questions/6206977/copying-c-abstract-classes/…)
 
Welcome.
 
10x. Specifically, is it true that the NVI idiom here helps detect slicing? (I think so)
 
*this can't be sliced in a member function.
 
It attempts to detect a derived class which forgot to implement its own clone method
 
10:58 AM
That's fine but that's completely unrelated to slicing.
 
If a class forgets to implement its own clone method, then you can get slicing.
 
And the NVI here refactors the checking code all in one point.
 
For example see the comments to the accepted answer
Yes, that's the point... (the checking in one point)
 
Since the copy constructor of the base class is protected in your answer, how can slicing happens?
 
When a derived class forgets to implement its own clone method. This is actually what happened in the original version of the accepted answer
 
11:00 AM
Then it won't compile because DoClone is pure virtual
 
Not if it is derived from a derived class which DOES implement doClone...
 
Which is different than the OP or any answer (including your own).
 
Yes, but I think that this should be the idiomatic way to write clone methods. And again, this would have caught the issue in the accepted answer
 
That's fine.
Someone could argue that putting the burden of cloning in the base class is wrong and instead CRTP should be idiomatic, too.
Can't remember how that works for hierarchies though
 
What burden in the base class? The base class only adds a runtime check that slicing didn't occur. Everything else is the same as the other answers...
 
11:06 AM
Terminology nitpick: an assertion is not the same as a runtime check.
 
Yes :-), but I think you got my meaning..
 
Ack. I meant the burden put on by the base class (i.e. requiring the derived types to implement and so on). It's another design strategy that may or may not be applicable here, I can't concentrate on this.
 
But to avoid slicing, derived classes should implement their own clone method. How else can you ensure this?
 
11:30 AM
clone methods suck
 
What are the alternatives?
 
usually, any design involving their necessity can be improved upon quite readily
if you find yourself needing one, there's a good chance your design needs a helping hand
like in the OP's code
he has a lovely polymorphic orgasm, but ultimately, it would be much bloody easier on him to just have deque<A> and deque<B>
by the way, nice to see you here
 
Nice to be here. So, basically you're saying to prefer generic vs. OO... :-)
 
always
if you can find a solution that involves a template, prefer it over a solution that involves a virtual function
inheritance is incredibly brittle and a Bad Ideaâ„¢, except where it's absolutely necessary
 
OK. Can be problematic with legacy code. Will keep in mind when writing new code.
 
11:37 AM
is it absolutely necessary that he puts both A and B objects in the same deque just to save having to call the same iteration function twice?
no
that's true
but hey, legacy code tends to have plenty of other problems apart from just sub-optimal design at this level
 
:-). The only other issue is the higher learning curve. But life would be boring otherwise.
 
well
I'm not gonna pretend that generic programming is the easiest thing ever
and the implementation in C++ can be a fiddly, fiddly bitch
and I'll grant you that sometimes, it's just not worth it, and there are problems generic can't solve that OOP can
but in general, generic > OOP
after all, the most useful Standard classes are both generic and OOP
even OOP-orgasm languages like Java and C# have had to admit how awesome generic programming is
and it's only going to become stronger when the implementation gets better, because templates suck
 
Just pushed my "C++ Templates - the Complete Guide" up my reading queue.
 
the thing about templates is
if your program doesn't work, the compiler throws an error
and that error might be long-winded, and it might be sucky, but it's sure as hell better than a failure at run-time
 
100Kb+ compile-time errors FTW.
 
11:51 AM
Do you experience with clang? Are its error messages with regard to templates also better than gcc?
 
I use MSVC myself
 
0
Q: destructor of a singleton class is called twice!!

srinuvenui have the code as below : class Singleton { private: int i; static bool stnflag; static Singleton* single; Singleton(int a) { i=a; } public: static Singleton* getinstance(int); void function(); ...

It's not just that people think they need a singleton. It's also that they don't even know how to use one.
 
12:13 PM
Everything i make is a static singleton!
 
Good morning
 
My classes always allow only rand() instances.
If it happens to be a 0, tough.
No instances for you.
 
Xeo
#define NULL rand() & 1
 
12:29 PM
lol
sucks to have nullptr huh?
 
#define nullptr rand() & 1
Big deal.
 
Xeo
@DeadMG People who use nullptr shouldn't be punished tho'
 
fair play
but your define won't compile
char* p = NULL; oops!
 
Xeo
Pff
then
#define return Bomb(); return with the appropriate Bomb() function
 
lol
 
Xeo
12:33 PM
That explodes every 100 returns
 
int factorial(int i) { if (i == 1) return 1; else return i * factorial(i - 1); }
oops- your macro just blew the branching
 
Who cares. :P
 
Xeo
12:56 PM
@DeadMG mimimi
 
1:09 PM
@Xeo hahaha
 
1:33 PM
2
Q: Building a Linux Kernel with Visual Studio 2010

Eric SeiglerDoes anyone have step-by-step instructions on how to build a Linux kernel using Visual Studio 2010? I've tried to search for the solution to this question directly, but no joy. A few things I have been able to find out: The Linux kernel is built using the GNU C compiler, so a prerequisite woul...

this is the most absurd quesiton ive seen
 
I think I've seen worst, but yeah this one ranks pretty high in absurdity.
Typing everything by hand sounds amazing.
You know what, why not just build the Linux kernel on a Linux machine, and then just type in the binary output on Windows?
 
heh it should build, since it's just c code and not even C++
 
@MartinhoFernandes that makes a nice answer, actually. I'd upvote that :-)
 
:)
 
even if you have a working kernel, you are FAR from having a linux system
thats what makes this question so stupid and absurd
 
1:40 PM
But once you have a kernel running, you're bootstrapped.
 
not really, how are you gonna boot it
 
Having typed in the GCC source and compiled it, you can compile a boot loader.
Then build a very basic shell, and you're set.
 
Done. I had to answer that question myself.
 
Kernel is unlikely to build under MSVC, anyway.
 
void swapChar(char *str, int i, int j) {

char tmp = str[i];
str[i] = str[j];
str[j] = tmp;
}
Why does this crash?
 
1:47 PM
I'm not sure it can be built by anything other than GCC reliably.
 
so they are using GCC proprietary stuff?
 
@Nils std::swap, don't use char*, also we don't know, maybe the pointer is bust, or the indexes are wrong.
 
replace that with standard c and it will work
 
@nils it shouldn't if str is big enough
 
indices are below the string length
 
1:48 PM
How you calling it?
 
"abc" is a const
 
Well, you can't do that.
Literals are const char*.
And are likely to be in a read-only memory.
 
it resides in unmodifiable region
 
ah
c has const?
 
1:50 PM
Especially when string pooling is on.
 
should be char str[]
 
@Nils String literals are not modifiable.
 
how can I create a modifiable string?
 
actually i think that is the infamous "undefined behaviour" but im not sure. call the standards police
 
Should be not C.
@Nils strdup.
 
1:52 PM
wait
 
The resulting string can be cleaned with free().
 
should I have to write const char *str = "asdf"
what about char str[] = {'a', 'b', 'c'}
?
 
That's not string literal.
It's an array initialised with character literals.
 
you are missing the concept here @nils
 
1:53 PM
guess so
 
Still, C, ugh.
 
char *str, str is a pointer, so it must POINT to something and that something lives in read only memory
 
Lately I can't stand even C++.
It's just so tiresome.
 
int *a doesn't have to point to something read only?
 
C is even more so
 
1:55 PM
@CatPlusPlus Heresy! Begone you devil!
 
Well, C is just crap.
 
I love C
 
nah Richie deserves the Turing award
 
Then you're a robot.
 
I get that C++ is hardly the best language EVAR!!!ONE!111!
but C is way, way worse
 
1:56 PM
I'd like to leave the land of undefined behaviour once and for all. :.
 
well you can of course code in assembly if you please
 
C taught me how computers "think"
 
C is not that far up from assembly.
 
honestly? I don't find avoiding UB a problem at all
just don't go near raw pointers or arrays and you'll be pretty much fine
 
Oh, it was just a fancy name for C++.
:P
 
1:57 PM
I am learning to appreciate C++ STL tho'
simply because I had to implement (more than once) std::vector std:queue etc
and with the STL it just works out of the box
 
I think I'm tired of the rebuild cycle the most, to be honest.
 
spend enough time in C++ and you will learn to appreciate, well, everything about C++ over C
 
well there is C for housewifes, also known as google go
 
sorry, what?
 
I find Go usable, contrary to C.
 

« first day (261 days earlier)      last day (4670 days later) »